Unverified Commit f21a9dd5 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix pageProps is missing when route changes (#38178)



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 50fa1705
......@@ -1857,8 +1857,9 @@ export default class Router implements BaseRouter {
).catch(() => {})
}
let flightInfo
if (routeInfo.__N_RSC) {
props.pageProps = Object.assign(props.pageProps, {
flightInfo = {
__flight__: useStreamedFlightData
? (
await this._getData(() =>
......@@ -1877,9 +1878,10 @@ export default class Router implements BaseRouter {
)
).data
: props.__flight__,
})
}
}
props.pageProps = Object.assign({}, props.pageProps, flightInfo)
routeInfo.props = props
routeInfo.route = route
routeInfo.query = query
......
export default function App({ Component, pageProps }) {
if (!pageProps || typeof pageProps !== 'object') {
throw new Error(
`Invariant: received invalid pageProps in _app, received ${pageProps}`
)
}
return <Component {...pageProps} />
}
......@@ -3,4 +3,13 @@ module.exports = {
locales: ['en', 'fr', 'nl', 'es'],
defaultLocale: 'en',
},
redirects() {
return [
{
source: '/to-new',
destination: '/dynamic/new',
permanent: false,
},
]
},
}
export default function App({ Component, pageProps }) {
if (!pageProps || typeof pageProps !== 'object') {
throw new Error(
`Invariant: received invalid pageProps in _app, received ${pageProps}`
)
}
return <Component {...pageProps} />
}
export default function Account() {
return (
<p id="dynamic" className="title">
Welcome to a /dynamic/[slug]
</p>
)
}
export function getServerSideProps() {
return {
props: {},
}
}
......@@ -26,6 +26,14 @@ describe('Middleware Redirect', () => {
testsWithLocale('/fr')
function tests() {
it('should redirect correctly with redirect in next.config.js', async () => {
const browser = await webdriver(next.url, '/')
await browser.eval('window.beforeNav = 1')
await browser.eval('window.next.router.push("/to-new")')
await browser.waitForElementByCss('#dynamic')
expect(await browser.eval('window.beforeNav')).toBe(1)
})
it('does not include the locale in redirects by default', async () => {
const res = await fetchViaHTTP(next.url, `/old-home`, undefined, {
redirect: 'manual',
......
export default function App({ Component, pageProps }) {
if (!pageProps || typeof pageProps !== 'object') {
throw new Error(
`Invariant: received invalid pageProps in _app, received ${pageProps}`
)
}
return <Component {...pageProps} />
}
export default function App({ Component, pageProps }) {
if (!pageProps || typeof pageProps !== 'object') {
throw new Error(
`Invariant: received invalid pageProps in _app, received ${pageProps}`
)
}
return <Component {...pageProps} />
}
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