diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 1208d86e4e08a..00958c73dc5aa 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -535,8 +535,10 @@ export default class Router implements BaseRouter { this.query = query // if auto prerendered and dynamic route wait to update asPath // until after mount to prevent hydration mismatch - this.asPath = - isDynamicRoute(pathname) && self.__NEXT_DATA__.autoExport ? pathname : as + const autoExportDynamic = + isDynamicRoute(pathname) && self.__NEXT_DATA__.autoExport + + this.asPath = autoExportDynamic ? pathname : as this.basePath = basePath this.sub = subscription this.clc = null @@ -550,7 +552,7 @@ export default class Router implements BaseRouter { this.isReady = !!( self.__NEXT_DATA__.gssp || self.__NEXT_DATA__.gip || - !self.location.search + (!autoExportDynamic && !self.location.search) ) if (process.env.__NEXT_I18N_SUPPORT) { diff --git a/test/integration/build-output/test/index.test.js b/test/integration/build-output/test/index.test.js index 208060cb80e12..36efddc1d58f1 100644 --- a/test/integration/build-output/test/index.test.js +++ b/test/integration/build-output/test/index.test.js @@ -101,7 +101,7 @@ describe('Build Output', () => { expect(parseFloat(err404Size) - 3.7).toBeLessThanOrEqual(0) expect(err404Size.endsWith('kB')).toBe(true) - expect(parseFloat(err404FirstLoad)).toBeCloseTo(65.4, 1) + expect(parseFloat(err404FirstLoad)).toBeCloseTo(65.5, 1) expect(err404FirstLoad.endsWith('kB')).toBe(true) expect(parseFloat(sharedByAll)).toBeCloseTo(62, 1) diff --git a/test/integration/router-is-ready/pages/auto-export.js b/test/integration/router-is-ready/pages/auto-export/[slug].js similarity index 100% rename from test/integration/router-is-ready/pages/auto-export.js rename to test/integration/router-is-ready/pages/auto-export/[slug].js diff --git a/test/integration/router-is-ready/pages/auto-export/index.js b/test/integration/router-is-ready/pages/auto-export/index.js new file mode 100644 index 0000000000000..f325029ae5880 --- /dev/null +++ b/test/integration/router-is-ready/pages/auto-export/index.js @@ -0,0 +1,18 @@ +import { useRouter } from 'next/router' + +export default function Page(props) { + const router = useRouter() + + if (typeof window !== 'undefined') { + if (!window.isReadyValues) { + window.isReadyValues = [] + } + window.isReadyValues.push(router.isReady) + } + + return ( + <> +

auto-export page

+ + ) +} diff --git a/test/integration/router-is-ready/test/index.test.js b/test/integration/router-is-ready/test/index.test.js index b2a9509e52a02..659b4decd1bb4 100644 --- a/test/integration/router-is-ready/test/index.test.js +++ b/test/integration/router-is-ready/test/index.test.js @@ -49,6 +49,16 @@ function runTests(isDev) { expect(await browser.eval('window.isReadyValues')).toEqual([false, true]) }) + it('isReady should be true after query update for dynamic auto-export page without query', async () => { + const browser = await webdriver(appPort, '/auto-export/first') + expect(await browser.eval('window.isReadyValues')).toEqual([false, true]) + }) + + it('isReady should be true after query update for dynamic auto-export page with query', async () => { + const browser = await webdriver(appPort, '/auto-export/first?hello=true') + expect(await browser.eval('window.isReadyValues')).toEqual([false, true]) + }) + it('isReady should be true after query update for getStaticProps page with query', async () => { const browser = await webdriver(appPort, '/gsp?hello=world') expect(await browser.eval('window.isReadyValues')).toEqual([false, true])