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(
},
]
: []),
...(webServerRuntime && hasServerComponents
...(hasServerComponents && webServerRuntime
? [
{
...codeCondition,
......
......@@ -42,17 +42,18 @@ async function parseImportsInfo(
// When importing from a server component, ignore
const importSource = node.source.value
if (
!(
isClientComponent(importSource, pageExtensions) ||
isNextComponent(importSource) ||
isImageImport(importSource)
)
) {
continue
}
// For the client compilation, we have to always import the component to
// ensure that all dependencies are tracked.
if (!isClientCompilation) {
if (
!(
isClientComponent(importSource, pageExtensions) ||
isNextComponent(importSource) ||
isImageImport(importSource)
)
) {
continue
}
transformedSource += source.substr(
lastIndex,
node.source.start - lastIndex
......@@ -104,5 +105,6 @@ export default async function transformSource(
const defaultExportNoop = isClientCompilation
? `\nexport default function Comp(){}\nComp.__next_rsc__=1`
: ''
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) {
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 }) {
......
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