23ac4351f4
From https://github.com/vercel/next.js/pull/20628, when the page is rendered server-side, `Router`'s `isReady` field needs to be initially set to `true`. However, when `_app` has custom `getInitialProps`, it seems that it is not the case, even though the page is rendered on the server. This leads to a bug that `Router.isReady` is never set to `true`. This pull request fixes the problem by fixing the initial calculation logic of `isReady` of `Router`. ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [x] Make sure the linting passes
32 lines
660 B
JavaScript
32 lines
660 B
JavaScript
import { useRouter } from 'next/router'
|
|
import { useLayoutEffect } from 'react'
|
|
|
|
export default function Page(props) {
|
|
const router = useRouter()
|
|
|
|
if (typeof window !== 'undefined') {
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
useLayoutEffect(() => {
|
|
if (!window.isReadyValues) {
|
|
window.isReadyValues = []
|
|
}
|
|
window.isReadyValues.push(router.isReady)
|
|
}, [router])
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<p id="gsp">gsp page</p>
|
|
<p id="props">{JSON.stringify(props)}</p>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export const getStaticProps = () => {
|
|
return {
|
|
props: {
|
|
hello: 'world',
|
|
random: Math.random(),
|
|
},
|
|
}
|
|
}
|