Skip to content

Commit

Permalink
fix rspack flight client entry plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Feb 6, 2025
1 parent 9876169 commit d03e52b
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@next/third-parties": "workspace:*",
"@opentelemetry/api": "1.4.1",
"@picocss/pico": "1.5.10",
"@rspack/core": "npm:@rspack-canary/core@1.2.0-canary-d6ded4dc-20250129035136",
"@rspack/core": "npm:@rspack-canary/core@1.2.0-canary-ef771fc5-20250206101425",
"@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55",
"@swc/core": "1.9.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@swc/counter": "0.1.3",
"@swc/helpers": "0.5.15",
"enhanced-resolve": "5.17.1",
"@rspack/core": "npm:@rspack-canary/core@1.2.0-canary-d6ded4dc-20250129035136",
"@rspack/core": "npm:@rspack-canary/core@1.2.0-canary-ef771fc5-20250206101425",
"@rspack/plugin-react-refresh": "1.0.1",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001579",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const flightClientModuleLoader: webpack.LoaderDefinitionFunction =
// Assign the RSC meta information to buildInfo.
const buildInfo = getModuleBuildInfo(this._module)
buildInfo.rsc = getRSCModuleInformation(source, false)
let prefix = ''
if (process.env.BUILTIN_FLIGHT_CLIENT_ENTRY_PLUGIN) {
const rscModuleInformationJson = JSON.stringify(buildInfo.rsc)
source =
`/* __rspack_internal_rsc_module_information_do_not_use__ ${rscModuleInformationJson} */\n` +
source
prefix = `/* __rspack_internal_rsc_module_information_do_not_use__ ${rscModuleInformationJson} */\n`
source = prefix + source
}

// This is a server action entry module in the client layer. We need to
Expand All @@ -29,11 +29,14 @@ const flightClientModuleLoader: webpack.LoaderDefinitionFunction =
// production mode. In development mode, we want to preserve the original
// modules (as transformed by SWC) to ensure that source mapping works.
if (buildInfo.rsc.actionIds && process.env.NODE_ENV === 'production') {
return Object.entries(buildInfo.rsc.actionIds)
.map(([id, name]) => {
return `export { ${name} } from 'next-flight-server-reference-proxy-loader?id=${id}&name=${name}!'`
})
.join('\n')
return (
prefix +
Object.entries(buildInfo.rsc.actionIds)
.map(([id, name]) => {
return `export { ${name} } from 'next-flight-server-reference-proxy-loader?id=${id}&name=${name}!'`
})
.join('\n')
)
}

return this.callback(null, source, sourceMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function transformSource(
// Exclude next internal files which are not marked as client files
const buildInfo = getModuleBuildInfo(module)
buildInfo.rsc = getRSCModuleInformation(source, true)
let prefix
let prefix = ''
if (process.env.BUILTIN_FLIGHT_CLIENT_ENTRY_PLUGIN) {
const rscModuleInformationJson = JSON.stringify(buildInfo.rsc)
prefix = `/* __rspack_internal_rsc_module_information_do_not_use__ ${rscModuleInformationJson} */\n`
Expand Down Expand Up @@ -115,12 +115,11 @@ export default function transformSource(
return
}

let esmSource = `\
let esmSource =
prefix +
`\
import { registerClientReference } from "react-server-dom-webpack/server.edge";
`
if (prefix) {
esmSource = prefix + esmSource
}
for (const ref of clientRefs) {
if (ref === 'default') {
esmSource += `export default registerClientReference(
Expand All @@ -145,14 +144,13 @@ ${JSON.stringify(ref)},

return this.callback(null, esmSource, sourceMap)
} else if (assumedSourceType === 'commonjs') {
let cjsSource = `\
let cjsSource =
prefix +
`\
const { createProxy } = require("${MODULE_PROXY_PATH}")
module.exports = createProxy(${stringifiedResourceKey})
`
if (prefix) {
cjsSource = prefix + cjsSource
}
return this.callback(null, cjsSource, sourceMap)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class RspackFlightClientEntryPlugin {
},
stateCb: (state: any) => {
Object.assign(pluginState.serverActions, state.serverActions)
Object.assign(pluginState.edgeServerActions, state.edgeServerActions)
Object.assign(
pluginState.serverActionModules,
state.serverActionModules
Expand Down
Loading

0 comments on commit d03e52b

Please sign in to comment.