Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure isReady is set correctly for auto static dynamic route #20729

Merged
merged 2 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions test/integration/router-is-ready/pages/auto-export/index.js
Original file line number Diff line number Diff line change
@@ -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 (
<>
<p id="auto-export">auto-export page</p>
</>
)
}
10 changes: 10 additions & 0 deletions test/integration/router-is-ready/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down