Unverified Commit 3d9c21bb authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Include router context as rsc shared dep (#37320)

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
parent 67180687
...@@ -936,6 +936,9 @@ export default async function getBaseWebpackConfig( ...@@ -936,6 +936,9 @@ export default async function getBaseWebpackConfig(
include: [dir, /next[\\/]dist[\\/]pages/], 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 = { let webpackConfig: webpack.Configuration = {
parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined, parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined,
// @ts-ignore // @ts-ignore
...@@ -1029,7 +1032,7 @@ export default async function getBaseWebpackConfig( ...@@ -1029,7 +1032,7 @@ export default async function getBaseWebpackConfig(
enforce: true, enforce: true,
name: 'rsc-runtime-deps', name: 'rsc-runtime-deps',
filename: 'rsc-runtime-deps.js', filename: 'rsc-runtime-deps.js',
test: /(node_modules\/react\/|\/shared\/lib\/head-manager-context\.js|node_modules\/styled-jsx\/)/, test: rscSharedRegex,
}, },
} }
: undefined : undefined
...@@ -1284,7 +1287,7 @@ export default async function getBaseWebpackConfig( ...@@ -1284,7 +1287,7 @@ export default async function getBaseWebpackConfig(
// Move shared dependencies from sc_server and sc_client into the // Move shared dependencies from sc_server and sc_client into the
// same layer. // same layer.
{ {
test: /(node_modules\/react\/|\/shared\/lib\/head-manager-context\.js|node_modules\/styled-jsx\/)/, test: rscSharedRegex,
layer: 'rsc_shared_deps', layer: 'rsc_shared_deps',
}, },
] ]
......
import { useRouter } from 'next/router'
export default () => {
const { pathname } = useRouter()
return <div>{`router pathname: ${pathname}`}</div>
}
import { parse } from 'url' import { parse } from 'url'
import RouterPath from '../../components/router-path.client'
export default function Pid({ text, pathname }) { export default function Pid({ text, pathname }) {
return ( return (
<> <>
<div>{`query: ${text}`}</div> <div>{`query: ${text}`}</div>
<div>{`pathname: ${pathname}`}</div> <div>{`pathname: ${pathname}`}</div>
<RouterPath />
</> </>
) )
} }
......
...@@ -129,6 +129,7 @@ export default function (context, { runtime, env }) { ...@@ -129,6 +129,7 @@ export default function (context, { runtime, env }) {
expect(dynamicRoute1HTML).toContain('pathname: /routes/dynamic') expect(dynamicRoute1HTML).toContain('pathname: /routes/dynamic')
expect(dynamicRoute2HTML).toContain('query: dynamic2') expect(dynamicRoute2HTML).toContain('query: dynamic2')
expect(dynamicRoute2HTML).toContain('pathname: /routes/dynamic') expect(dynamicRoute2HTML).toContain('pathname: /routes/dynamic')
expect(dynamicRoute1HTML).toContain('router pathname: /routes/[dynamic]')
}) })
it('should be able to navigate between rsc pages', async () => { it('should be able to navigate between rsc pages', async () => {
......
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