@@ -48,6 +48,10 @@ export type ActionManifest = {
48
48
workers : {
49
49
[ name : string ] : string | number
50
50
}
51
+ // Record which layer the action is in (sc_server or sc_action), in the specific entry.
52
+ layer : {
53
+ [ name : string ] : string
54
+ }
51
55
}
52
56
}
53
57
}
@@ -56,8 +60,21 @@ const pluginState = getProxiedPluginState({
56
60
// A map to track "action" -> "list of bundles".
57
61
serverActions : { } as ActionManifest [ 'node' ] ,
58
62
edgeServerActions : { } as ActionManifest [ 'edge' ] ,
59
- actionModServerId : { } as Record < string , string | number > ,
60
- actionModEdgeServerId : { } as Record < string , string | number > ,
63
+
64
+ actionModServerId : { } as Record <
65
+ string ,
66
+ {
67
+ server ?: string | number
68
+ client ?: string | number
69
+ }
70
+ > ,
71
+ actionModEdgeServerId : { } as Record <
72
+ string ,
73
+ {
74
+ server ?: string | number
75
+ client ?: string | number
76
+ }
77
+ > ,
61
78
62
79
// Manifest of CSS entry files for server/edge server.
63
80
serverCSSManifest : { } as ClientCSSReferenceManifest ,
@@ -170,6 +187,7 @@ export class ClientReferenceEntryPlugin {
170
187
171
188
const addActionEntryList : Array < ReturnType < typeof this . injectActionEntry > > =
172
189
[ ]
190
+ const actionMapsPerEntry : Record < string , Map < string , string [ ] > > = { }
173
191
174
192
// For each SC server compilation entry, we need to create its corresponding
175
193
// client component entry.
@@ -247,19 +265,31 @@ export class ClientReferenceEntryPlugin {
247
265
)
248
266
)
249
267
} else {
250
- addActionEntryList . push (
251
- this . injectActionEntry ( {
252
- compiler,
253
- compilation,
254
- actions : actionEntryImports ,
255
- entryName : name ,
256
- bundlePath : name ,
257
- } )
258
- )
268
+ if ( ! actionMapsPerEntry [ name ] ) {
269
+ actionMapsPerEntry [ name ] = new Map ( )
270
+ }
271
+ actionMapsPerEntry [ name ] = new Map ( [
272
+ ...actionMapsPerEntry [ name ] ,
273
+ ...actionEntryImports ,
274
+ ] )
259
275
}
260
276
}
261
277
} )
262
278
279
+ for ( const [ name , actionEntryImports ] of Object . entries (
280
+ actionMapsPerEntry
281
+ ) ) {
282
+ addActionEntryList . push (
283
+ this . injectActionEntry ( {
284
+ compiler,
285
+ compilation,
286
+ actions : actionEntryImports ,
287
+ entryName : name ,
288
+ bundlePath : name ,
289
+ } )
290
+ )
291
+ }
292
+
263
293
// To collect all CSS imports and action imports for a specific entry
264
294
// including the ones that are in the client graph, we need to store a
265
295
// map for client boundary dependencies.
@@ -293,6 +323,7 @@ export class ClientReferenceEntryPlugin {
293
323
// client layer.
294
324
compilation . hooks . finishModules . tapPromise ( PLUGIN_NAME , ( ) => {
295
325
const addedClientActionEntryList : Promise < any > [ ] = [ ]
326
+ const actionMapsPerClientEntry : Record < string , Map < string , string [ ] > > = { }
296
327
297
328
forEachEntryModule ( compilation , ( { name, entryModule } ) => {
298
329
const actionEntryImports = new Map < string , string [ ] > ( )
@@ -324,18 +355,31 @@ export class ClientReferenceEntryPlugin {
324
355
}
325
356
326
357
if ( actionEntryImports . size > 0 ) {
327
- addedClientActionEntryList . push (
328
- this . injectActionEntry ( {
329
- compiler,
330
- compilation,
331
- actions : actionEntryImports ,
332
- entryName : name ,
333
- bundlePath : name ,
334
- fromClient : true ,
335
- } )
336
- )
358
+ if ( ! actionMapsPerClientEntry [ name ] ) {
359
+ actionMapsPerClientEntry [ name ] = new Map ( )
360
+ }
361
+ actionMapsPerClientEntry [ name ] = new Map ( [
362
+ ...actionMapsPerClientEntry [ name ] ,
363
+ ...actionEntryImports ,
364
+ ] )
337
365
}
338
366
} )
367
+
368
+ for ( const [ name , actionEntryImports ] of Object . entries (
369
+ actionMapsPerClientEntry
370
+ ) ) {
371
+ addedClientActionEntryList . push (
372
+ this . injectActionEntry ( {
373
+ compiler,
374
+ compilation,
375
+ actions : actionEntryImports ,
376
+ entryName : name ,
377
+ bundlePath : name ,
378
+ fromClient : true ,
379
+ } )
380
+ )
381
+ }
382
+
339
383
return Promise . all ( addedClientActionEntryList )
340
384
} )
341
385
@@ -719,6 +763,7 @@ export class ClientReferenceEntryPlugin {
719
763
const actionsArray = Array . from ( actions . entries ( ) )
720
764
const actionLoader = `next-flight-action-entry-loader?${ stringify ( {
721
765
actions : JSON . stringify ( actionsArray ) ,
766
+ __client_imported__ : fromClient ,
722
767
} ) } !`
723
768
724
769
const currentCompilerServerActions = this . isEdgeServer
@@ -730,9 +775,13 @@ export class ClientReferenceEntryPlugin {
730
775
if ( typeof currentCompilerServerActions [ id ] === 'undefined' ) {
731
776
currentCompilerServerActions [ id ] = {
732
777
workers : { } ,
778
+ layer : { } ,
733
779
}
734
780
}
735
781
currentCompilerServerActions [ id ] . workers [ bundlePath ] = ''
782
+ currentCompilerServerActions [ id ] . layer [ bundlePath ] = fromClient
783
+ ? WEBPACK_LAYERS . action
784
+ : WEBPACK_LAYERS . server
736
785
}
737
786
}
738
787
@@ -793,19 +842,28 @@ export class ClientReferenceEntryPlugin {
793
842
mod . request &&
794
843
/ n e x t - f l i g h t - a c t i o n - e n t r y - l o a d e r / . test ( mod . request )
795
844
) {
796
- if ( this . isEdgeServer ) {
797
- pluginState . actionModEdgeServerId [ chunkGroup . name ] = modId
798
- } else {
799
- pluginState . actionModServerId [ chunkGroup . name ] = modId
845
+ const fromClient = / & _ _ c l i e n t _ i m p o r t e d _ _ = t r u e / . test ( mod . request )
846
+
847
+ const mapping = this . isEdgeServer
848
+ ? pluginState . actionModEdgeServerId
849
+ : pluginState . actionModServerId
850
+
851
+ if ( ! mapping [ chunkGroup . name ] ) {
852
+ mapping [ chunkGroup . name ] = { }
800
853
}
854
+ mapping [ chunkGroup . name ] [ fromClient ? 'client' : 'server' ] = modId
801
855
}
802
856
} )
803
857
804
858
const serverActions : ActionManifest [ 'node' ] = { }
805
859
for ( let id in pluginState . serverActions ) {
806
860
const action = pluginState . serverActions [ id ]
807
861
for ( let name in action . workers ) {
808
- action . workers [ name ] = pluginState . actionModServerId [ name ]
862
+ const modId =
863
+ pluginState . actionModServerId [ name ] [
864
+ action . layer [ name ] === WEBPACK_LAYERS . action ? 'client' : 'server'
865
+ ]
866
+ action . workers [ name ] = modId !
809
867
}
810
868
serverActions [ id ] = action
811
869
}
@@ -814,7 +872,11 @@ export class ClientReferenceEntryPlugin {
814
872
for ( let id in pluginState . edgeServerActions ) {
815
873
const action = pluginState . edgeServerActions [ id ]
816
874
for ( let name in action . workers ) {
817
- action . workers [ name ] = pluginState . actionModEdgeServerId [ name ]
875
+ const modId =
876
+ pluginState . actionModEdgeServerId [ name ] [
877
+ action . layer [ name ] === WEBPACK_LAYERS . action ? 'client' : 'server'
878
+ ]
879
+ action . workers [ name ] = modId !
818
880
}
819
881
edgeServerActions [ id ] = action
820
882
}
0 commit comments