From d85d2fb6124488977c9ba6590ab1edc1ae3ba6b4 Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Sun, 25 Aug 2019 10:53:23 +0100 Subject: [PATCH] Revert "feat: function watchQuery (#6245)" (#6296) This reverts commit 3c61830a0d7eb4433b27e82cc3533e69bc005dc3. --- packages/vue-app/template/client.js | 14 ++++++----- test/e2e/basic.browser.test.js | 18 -------------- .../pages/scroll-to-top/watch-query-fn.vue | 24 ------------------- 3 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 test/fixtures/basic/pages/scroll-to-top/watch-query-fn.vue diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index 04b220b173..2b67e2517d 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -279,7 +279,6 @@ async function render(to, from, next) { // Get route's matched components const matches = [] const Components = getMatchedComponents(to, matches) - const instances = getMatchedComponentsInstances(to) // If no Components matched, generate 404 if (!Components.length) { @@ -372,8 +371,6 @@ async function render(to, from, next) { Component._dataRefresh = true } else if (Array.isArray(watchQuery)) { Component._dataRefresh = watchQuery.some(key => this._diffQuery[key]) - } else if (typeof watchQuery === 'function') { - Component._dataRefresh = watchQuery.apply(instances[i], [to.query, from.query]) } } if (!this._hadError && this._isMounted && !Component._dataRefresh) { @@ -494,13 +491,18 @@ function showNextPage(to) { function fixPrepatch(to, ___) { if (this._pathChanged === false && this._queryChanged === false) return - const instances = getMatchedComponentsInstances(to) - const Components = getMatchedComponents(to) + const matches = [] + const instances = getMatchedComponentsInstances(to, matches) + const Components = getMatchedComponents(to, matches) Vue.nextTick(() => { instances.forEach((instance, i) => { if (!instance || instance._isDestroyed) return - + // if ( + // !this._queryChanged && + // to.matched[matches[i]].path.indexOf(':') === -1 && + // to.matched[matches[i]].path.indexOf('*') === -1 + // ) return // If not a dynamic route, skip if ( instance.constructor._dataRefresh && Components[i] === instance.constructor && diff --git a/test/e2e/basic.browser.test.js b/test/e2e/basic.browser.test.js index bc667f09df..8584efedd2 100644 --- a/test/e2e/basic.browser.test.js +++ b/test/e2e/basic.browser.test.js @@ -180,24 +180,6 @@ describe('basic browser', () => { page.close() }) - test('/scroll-to-top in the same page with watchQuery function', async () => { - const page = await browser.page(url('/scroll-to-top/watch-query-fn')) - await page.evaluate(() => window.scrollBy(0, window.innerHeight)) - await page.nuxt.navigate('/scroll-to-top/watch-query-fn?other=1') - let pageYOffset = await page.evaluate(() => window.pageYOffset) - expect(pageYOffset).toBeGreaterThan(0) - await page.nuxt.go(-1) - pageYOffset = await page.evaluate(() => window.pageYOffset) - expect(pageYOffset).toBeGreaterThan(0) - await page.nuxt.navigate('/scroll-to-top/watch-query-fn?test=1') - pageYOffset = await page.evaluate(() => window.pageYOffset) - expect(pageYOffset).toBe(0) - await page.nuxt.go(-1) - pageYOffset = await page.evaluate(() => window.pageYOffset) - expect(pageYOffset).toBe(0) - page.close() - }) - test('/validate should display a 404', async () => { await page.nuxt.navigate('/validate') diff --git a/test/fixtures/basic/pages/scroll-to-top/watch-query-fn.vue b/test/fixtures/basic/pages/scroll-to-top/watch-query-fn.vue deleted file mode 100644 index 4d49ec094a..0000000000 --- a/test/fixtures/basic/pages/scroll-to-top/watch-query-fn.vue +++ /dev/null @@ -1,24 +0,0 @@ - - - - -