Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix named export missing from client components #34974

Merged
merged 5 commits into from Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -1598,7 +1598,12 @@ export default async function getBaseWebpackConfig(
if (!webpack5Config.optimization) {
webpack5Config.optimization = {}
}
webpack5Config.optimization.providedExports = false

// For Server Components, it's necessary to have provided exports collected
// to generate the correct flight manifest.
if (!hasServerComponents) {
webpack5Config.optimization.providedExports = false
}
webpack5Config.optimization.usedExports = false
}

Expand Down
Expand Up @@ -75,6 +75,11 @@ async function parseExportNamesInto(
}
}
continue
case 'ExportDeclaration':
if (node.declaration?.identifier) {
addExportNames(names, node.declaration.identifier)
}
continue
default:
break
}
Expand Down
13 changes: 8 additions & 5 deletions packages/next/build/webpack/plugins/flight-manifest-plugin.ts
Expand Up @@ -82,12 +82,15 @@ export class FlightManifestPlugin {
const moduleExports: any = json[resource] || {}

const exportsInfo = compilation.moduleGraph.getExportsInfo(mod)
const providedExports = exportsInfo.getProvidedExports()
const moduleExportedKeys = ['', '*'].concat(
// TODO: improve exports detection
providedExports === true || providedExports == null
? 'default'
: providedExports
[...exportsInfo.exports]
.map((exportInfo) => {
if (exportInfo.provided) {
return exportInfo.name
}
return null
})
.filter(Boolean)
)

moduleExportedKeys.forEach((name) => {
Expand Down
@@ -0,0 +1,3 @@
export function Named() {
return 'named export: named.client'
}
@@ -1,4 +1,6 @@
import Foo from '../components/foo.client'
import { Named } from '../components/named.client'

import Link from 'next/link'

const envVar = process.env.ENV_VAR_TEST
Expand All @@ -11,6 +13,9 @@ export default function Index({ header, router }) {
<div>{'path:' + router.pathname}</div>
<div>{'env:' + envVar}</div>
<div>{'header:' + header}</div>
<div>
<Named />
</div>
<div>
<Foo />
</div>
Expand Down
Expand Up @@ -28,6 +28,7 @@ export default function (context, { runtime, env }) {
expect(homeHTML).toContain('header:test-util')
expect(homeHTML).toContain('path:/')
expect(homeHTML).toContain('foo.client')
expect(homeHTML).toContain('named.client')
})

it('should reuse the inline flight response without sending extra requests', async () => {
Expand Down