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

Fix pageProps is missing when route changes #38178

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/next/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/middleware-general/app/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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} />
}
9 changes: 9 additions & 0 deletions test/e2e/middleware-redirects/app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ module.exports = {
locales: ['en', 'fr', 'nl', 'es'],
defaultLocale: 'en',
},
redirects() {
return [
{
source: '/to-new',
destination: '/dynamic/new',
permanent: false,
},
]
},
}
8 changes: 8 additions & 0 deletions test/e2e/middleware-redirects/app/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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} />
}
13 changes: 13 additions & 0 deletions test/e2e/middleware-redirects/app/pages/dynamic/[slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function Account() {
return (
<p id="dynamic" className="title">
Welcome to a /dynamic/[slug]
</p>
)
}

export function getServerSideProps() {
return {
props: {},
}
}
8 changes: 8 additions & 0 deletions test/e2e/middleware-redirects/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/middleware-rewrites/app/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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} />
}
8 changes: 8 additions & 0 deletions test/integration/dynamic-routing/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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} />
}