Skip to content

Commit 9e41a31

Browse files
committed
Set async flag in server module map only if module is actually async
1 parent b86ae3f commit 9e41a31

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

packages/next/src/build/webpack/loaders/next-flight-action-entry-loader.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ function nextFlightActionEntryLoader(this: any) {
2323
${individualActions
2424
.map(([id, path, name]) => {
2525
// Re-export the same functions from the original module path as action IDs.
26-
return `
27-
const { ${name}: _${id} } = await import(${JSON.stringify(path)});
28-
export { _${id} as "${id}" };
29-
`
26+
return `export { ${name} as "${id}" } from ${JSON.stringify(path)}`
3027
})
3128
.join('\n')}
3229
`

packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const PLUGIN_NAME = 'FlightClientEntryPlugin'
5555
type Actions = {
5656
[actionId: string]: {
5757
workers: {
58-
[name: string]: string | number
58+
[name: string]: { moduleId: string | number; async: boolean }
5959
}
6060
// Record which layer the action is in (rsc or sc_action), in the specific entry.
6161
layer: {
@@ -79,15 +79,15 @@ const pluginState = getProxiedPluginState({
7979
actionModServerId: {} as Record<
8080
string,
8181
{
82-
server?: string | number
83-
client?: string | number
82+
server?: { moduleId: string | number; async: boolean }
83+
client?: { moduleId: string | number; async: boolean }
8484
}
8585
>,
8686
actionModEdgeServerId: {} as Record<
8787
string,
8888
{
89-
server?: string | number
90-
client?: string | number
89+
server?: { moduleId: string | number; async: boolean }
90+
client?: { moduleId: string | number; async: boolean }
9191
}
9292
>,
9393

@@ -879,7 +879,11 @@ export class FlightClientEntryPlugin {
879879
layer: {},
880880
}
881881
}
882-
currentCompilerServerActions[id].workers[bundlePath] = ''
882+
currentCompilerServerActions[id].workers[bundlePath] = {
883+
moduleId: '', // TODO: What's the meaning of this?
884+
async: false,
885+
}
886+
883887
currentCompilerServerActions[id].layer[bundlePath] = fromClient
884888
? WEBPACK_LAYERS.actionBrowser
885889
: WEBPACK_LAYERS.reactServerComponents
@@ -965,7 +969,10 @@ export class FlightClientEntryPlugin {
965969
if (!mapping[chunkGroup.name]) {
966970
mapping[chunkGroup.name] = {}
967971
}
968-
mapping[chunkGroup.name][fromClient ? 'client' : 'server'] = modId
972+
mapping[chunkGroup.name][fromClient ? 'client' : 'server'] = {
973+
moduleId: modId,
974+
async: compilation.moduleGraph.isAsync(mod),
975+
}
969976
}
970977
})
971978

packages/next/src/server/app-render/action-utils.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ export function createServerModuleMap({
1818
{},
1919
{
2020
get: (_, id: string) => {
21-
return {
22-
id: serverActionsManifest[
21+
const { moduleId, async } =
22+
serverActionsManifest[
2323
process.env.NEXT_RUNTIME === 'edge' ? 'edge' : 'node'
24-
][id].workers[normalizeWorkerPageName(pageName)],
25-
name: id,
26-
chunks: [],
27-
// Because of how next-flight-action-entry-loader creates the action
28-
// entry modules, we know that these become async. So we set the flag
29-
// accordingly.
30-
async: true,
31-
}
24+
][id].workers[normalizeWorkerPageName(pageName)]
25+
26+
return { id: moduleId, name: id, chunks: [], async }
3227
},
3328
}
3429
)

0 commit comments

Comments
 (0)