Unverified Commit 0fa233b7 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix client component imports are not being correctly tracked (#30853)

* ensure client components are correctly tracked in the client compilation

* fix test
parent 3aff5d4f
...@@ -1187,7 +1187,7 @@ export default async function getBaseWebpackConfig( ...@@ -1187,7 +1187,7 @@ export default async function getBaseWebpackConfig(
}, },
] ]
: []), : []),
...(webServerRuntime && hasServerComponents ...(hasServerComponents && webServerRuntime
? [ ? [
{ {
...codeCondition, ...codeCondition,
......
...@@ -42,6 +42,9 @@ async function parseImportsInfo( ...@@ -42,6 +42,9 @@ async function parseImportsInfo(
// When importing from a server component, ignore // When importing from a server component, ignore
const importSource = node.source.value const importSource = node.source.value
// For the client compilation, we have to always import the component to
// ensure that all dependencies are tracked.
if (!isClientCompilation) {
if ( if (
!( !(
isClientComponent(importSource, pageExtensions) || isClientComponent(importSource, pageExtensions) ||
...@@ -51,8 +54,6 @@ async function parseImportsInfo( ...@@ -51,8 +54,6 @@ async function parseImportsInfo(
) { ) {
continue continue
} }
if (!isClientCompilation) {
transformedSource += source.substr( transformedSource += source.substr(
lastIndex, lastIndex,
node.source.start - lastIndex node.source.start - lastIndex
...@@ -104,5 +105,6 @@ export default async function transformSource( ...@@ -104,5 +105,6 @@ export default async function transformSource(
const defaultExportNoop = isClientCompilation const defaultExportNoop = isClientCompilation
? `\nexport default function Comp(){}\nComp.__next_rsc__=1` ? `\nexport default function Comp(){}\nComp.__next_rsc__=1`
: '' : ''
return transformed + noop + defaultExportNoop return transformed + noop + defaultExportNoop
} }
import Foo from './foo.client'
export default function Bar() {
return (
<div>
bar.server.js: <Foo />
</div>
)
}
import Bar from '../components/bar.server'
export default function Multi() {
return <Bar />
}
...@@ -220,6 +220,12 @@ async function runBasicTests(context) { ...@@ -220,6 +220,12 @@ async function runBasicTests(context) {
expect(imageTag.attr('src')).toContain('data:image') expect(imageTag.attr('src')).toContain('data:image')
}) })
it('should support multi-level server component imports', async () => {
const html = await renderViaHTTP(context.appPort, '/multi')
expect(html).toContain('bar.server.js:')
expect(html).toContain('foo.client')
})
} }
function runSuite(suiteName, env, { runTests, before, after }) { function runSuite(suiteName, env, { runTests, before, after }) {
......
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