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,17 +42,18 @@ async function parseImportsInfo( ...@@ -42,17 +42,18 @@ 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
if ( // For the client compilation, we have to always import the component to
!( // ensure that all dependencies are tracked.
isClientComponent(importSource, pageExtensions) ||
isNextComponent(importSource) ||
isImageImport(importSource)
)
) {
continue
}
if (!isClientCompilation) { if (!isClientCompilation) {
if (
!(
isClientComponent(importSource, pageExtensions) ||
isNextComponent(importSource) ||
isImageImport(importSource)
)
) {
continue
}
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