Skip to content

Commit

Permalink
Include router context as rsc shared dep (#37320)
Browse files Browse the repository at this point in the history
Router context should be treated as rsc shared dep otherwise client component won't receive the instance in edge runtime

## Bug

- [x] Integration tests added
  • Loading branch information
huozhi authored May 30, 2022
1 parent 6718068 commit 3d9c21b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,9 @@ export default async function getBaseWebpackConfig(
include: [dir, /next[\\/]dist[\\/]pages/],
}

const rscSharedRegex =
/(node_modules\/react\/|\/shared\/lib\/(head-manager-context|router-context)\.js|node_modules\/styled-jsx\/)/

let webpackConfig: webpack.Configuration = {
parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined,
// @ts-ignore
Expand Down Expand Up @@ -1029,7 +1032,7 @@ export default async function getBaseWebpackConfig(
enforce: true,
name: 'rsc-runtime-deps',
filename: 'rsc-runtime-deps.js',
test: /(node_modules\/react\/|\/shared\/lib\/head-manager-context\.js|node_modules\/styled-jsx\/)/,
test: rscSharedRegex,
},
}
: undefined
Expand Down Expand Up @@ -1284,7 +1287,7 @@ export default async function getBaseWebpackConfig(
// Move shared dependencies from sc_server and sc_client into the
// same layer.
{
test: /(node_modules\/react\/|\/shared\/lib\/head-manager-context\.js|node_modules\/styled-jsx\/)/,
test: rscSharedRegex,
layer: 'rsc_shared_deps',
},
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useRouter } from 'next/router'

export default () => {
const { pathname } = useRouter()
return <div>{`router pathname: ${pathname}`}</div>
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { parse } from 'url'
import RouterPath from '../../components/router-path.client'

export default function Pid({ text, pathname }) {
return (
<>
<div>{`query: ${text}`}</div>
<div>{`pathname: ${pathname}`}</div>
<RouterPath />
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default function (context, { runtime, env }) {
expect(dynamicRoute1HTML).toContain('pathname: /routes/dynamic')
expect(dynamicRoute2HTML).toContain('query: dynamic2')
expect(dynamicRoute2HTML).toContain('pathname: /routes/dynamic')
expect(dynamicRoute1HTML).toContain('router pathname: /routes/[dynamic]')
})

it('should be able to navigate between rsc pages', async () => {
Expand Down

0 comments on commit 3d9c21b

Please sign in to comment.