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

rsc: remove router injection #36101

Merged
merged 2 commits into from Apr 13, 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
4 changes: 2 additions & 2 deletions packages/next/server/render.tsx
Expand Up @@ -741,7 +741,7 @@ export async function renderToHTML(
AppTree: (props: any) => {
return (
<AppContainerWithIsomorphicFiberStructure>
{renderFlight(AppMod, ComponentMod, { ...props, router })}
{renderFlight(AppMod, ComponentMod, props)}
</AppContainerWithIsomorphicFiberStructure>
)
},
Expand Down Expand Up @@ -1216,7 +1216,7 @@ export async function renderToHTML(

// Pass router to the Server Component as a temporary workaround.
if (isServerComponent) {
props.pageProps = Object.assign({}, props.pageProps, { router })
props.pageProps = Object.assign({}, props.pageProps)
}
Comment on lines 1217 to 1220
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this comment and the whole if block redundant now?


// the response might be finished on the getInitialProps call
Expand Down
Expand Up @@ -3,11 +3,10 @@ import Nav from '../components/nav'
const envVar = process.env.ENV_VAR_TEST
const headerKey = 'x-next-test-client'

export default function Index({ header, router }) {
export default function Index({ header }) {
return (
<div>
<h1>{`component:index.server`}</h1>
<div>{'path:' + router.pathname}</div>
<div>{'env:' + envVar}</div>
<div>{'header:' + header}</div>
<Nav />
Expand Down
@@ -1,9 +1,8 @@
import Link from 'next/link'
import Nav from '../../components/nav'

export default function LinkPage({ router }) {
const { query } = router
const id = parseInt(query.id || '0', 10)
export default function LinkPage({ queryId }) {
const id = parseInt(queryId)
return (
<>
<h3 id="query">query:{id}</h3>
Expand All @@ -17,6 +16,10 @@ export default function LinkPage({ router }) {
)
}

export const config = {
runtime: 'edge',
export function getServerSideProps({ query }) {
return {
props: {
queryId: query.id || '0',
},
}
}
@@ -1,7 +1,11 @@
export default function Pid({ router }) {
return <div>{`query: ${router.query.dynamic}`}</div>
export default function Pid({ text }) {
return <div>{`query: ${text}`}</div>
}

export const config = {
runtime: 'edge',
export function getServerSideProps({ params }) {
return {
props: {
text: params.dynamic,
},
}
}
Expand Up @@ -19,7 +19,6 @@ export default function (context, { runtime, env }) {
expect(homeHTML).toContain('component:index.server')
expect(homeHTML).toContain('env:env_var_test')
expect(homeHTML).toContain('header:test-util')
expect(homeHTML).toContain('path:/')
})

it('should reuse the inline flight response without sending extra requests', async () => {
Expand Down