Commit a5ebe41a authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Delay updating asPath for auto exported pages (#8681)

* Delay updating asPath for auto exported pages

* Add additional test ensuring asPath is updated
parent 79090718
......@@ -163,7 +163,11 @@ export default async ({ webpackHMR: passedWebpackHMR } = {}) => {
await window.__NEXT_PRELOADREADY(dynamicIds)
}
router = createRouter(page, query, asPath, {
// if auto prerendered and dynamic route wait to update asPath
// until after mount to prevent hydration mismatch
const initialAsPath = isDynamicRoute(page) && data.nextExport ? page : asPath
router = createRouter(page, query, initialAsPath, {
initialProps: props,
pageLoader,
App,
......
......@@ -66,12 +66,19 @@ describe('Auto Export', () => {
runTests()
it('should show hydration warning from mismatching asPath', async () => {
it('should not show hydration warning from mismatching asPath', async () => {
const browser = await webdriver(appPort, '/zeit/cmnt-1')
await waitFor(500)
const numCaught = await browser.eval(`window.caughtWarns.length`)
expect(numCaught).toBe(1)
expect(numCaught).toBe(0)
})
it('should update asPath after mount', async () => {
const browser = await webdriver(appPort, '/zeit/cmnt-2')
await waitFor(500)
const html = await browser.eval(`document.documentElement.innerHTML`)
expect(html).toMatch(/\/zeit\/cmnt-2/)
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment