未验证 提交 88b6c472 编写于 作者: J JJ Kasper 提交者: GitHub

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

Follow-up to https://github.com/vercel/next.js/pull/20628 this ensures `isReady` is not initially true when the query isn't present but the page is an automatically statically optimized dynamic route
上级 9ff37855
......@@ -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) {
......
......@@ -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)
......
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>
</>
)
}
......@@ -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])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册