@@ -25,7 +25,7 @@ import {
25
25
UNDERSCORE_NOT_FOUND_ROUTE_ENTRY ,
26
26
} from '../../../shared/lib/constants'
27
27
import {
28
- getActions ,
28
+ getActionsFromBuildInfo ,
29
29
generateActionId ,
30
30
isClientComponentEntryModule ,
31
31
isCSSMod ,
@@ -356,10 +356,10 @@ export class FlightClientEntryPlugin {
356
356
...clientEntryToInject . clientComponentImports ,
357
357
...(
358
358
dedupedCSSImports [ clientEntryToInject . absolutePagePath ] || [ ]
359
- ) . reduce ( ( res , curr ) => {
359
+ ) . reduce < ClientComponentImports > ( ( res , curr ) => {
360
360
res [ curr ] = new Set ( )
361
361
return res
362
- } , { } as ClientComponentImports ) ,
362
+ } , { } ) ,
363
363
} ,
364
364
} )
365
365
@@ -529,27 +529,14 @@ export class FlightClientEntryPlugin {
529
529
const collectActionsInDep = ( mod : webpack . NormalModule ) : void => {
530
530
if ( ! mod ) return
531
531
532
- const modPath : string = mod . resourceResolveData ?. path || ''
533
- // We have to always use the resolved request here to make sure the
534
- // server and client are using the same module path (required by RSC), as
535
- // the server compiler and client compiler have different resolve configs.
536
- let modRequest : string =
537
- modPath + ( mod . resourceResolveData ?. query || '' )
538
-
539
- // For the barrel optimization, we need to use the match resource instead
540
- // because there will be 2 modules for the same file (same resource path)
541
- // but they're different modules and can't be deduped via `visitedModule`.
542
- // The first module is a virtual re-export module created by the loader.
543
- if ( mod . matchResource ?. startsWith ( BARREL_OPTIMIZATION_PREFIX ) ) {
544
- modRequest = mod . matchResource + ':' + modRequest
545
- }
532
+ const modResource = getModuleResource ( mod )
546
533
547
- if ( ! modRequest || visitedModule . has ( modRequest ) ) return
548
- visitedModule . add ( modRequest )
534
+ if ( ! modResource || visitedModule . has ( modResource ) ) return
535
+ visitedModule . add ( modResource )
549
536
550
- const actions = getActions ( mod )
537
+ const actions = getActionsFromBuildInfo ( mod )
551
538
if ( actions ) {
552
- collectedActions . set ( modRequest , actions )
539
+ collectedActions . set ( modResource , actions )
553
540
}
554
541
555
542
getModuleReferencesInOrder ( mod , compilation . moduleGraph ) . forEach (
@@ -578,8 +565,8 @@ export class FlightClientEntryPlugin {
578
565
ssrEntryModule ,
579
566
compilation . moduleGraph
580
567
) ) {
581
- const dependency = connection . dependency !
582
- const request = ( dependency as unknown as webpack . NormalModule ) . request
568
+ const depModule = connection . dependency
569
+ const request = ( depModule as unknown as webpack . NormalModule ) . request
583
570
584
571
// It is possible that the same entry is added multiple times in the
585
572
// connection graph. We can just skip these to speed up the process.
@@ -624,45 +611,26 @@ export class FlightClientEntryPlugin {
624
611
if ( ! mod ) return
625
612
626
613
const isCSS = isCSSMod ( mod )
614
+ const modResource = getModuleResource ( mod )
627
615
628
- const modPath : string = mod . resourceResolveData ?. path || ''
629
- const modQuery = mod . resourceResolveData ?. query || ''
630
- // We have to always use the resolved request here to make sure the
631
- // server and client are using the same module path (required by RSC), as
632
- // the server compiler and client compiler have different resolve configs.
633
- let modRequest : string = modPath + modQuery
634
-
635
- // Context modules don't have a resource path, we use the identifier instead.
636
- if ( mod . constructor . name === 'ContextModule' ) {
637
- modRequest = ( mod as any ) . _identifier
638
- }
639
-
640
- // For the barrel optimization, we need to use the match resource instead
641
- // because there will be 2 modules for the same file (same resource path)
642
- // but they're different modules and can't be deduped via `visitedModule`.
643
- // The first module is a virtual re-export module created by the loader.
644
- if ( mod . matchResource ?. startsWith ( BARREL_OPTIMIZATION_PREFIX ) ) {
645
- modRequest = mod . matchResource + ':' + modRequest
646
- }
647
-
648
- if ( ! modRequest ) return
649
- if ( visited . has ( modRequest ) ) {
650
- if ( clientComponentImports [ modRequest ] ) {
616
+ if ( ! modResource ) return
617
+ if ( visited . has ( modResource ) ) {
618
+ if ( clientComponentImports [ modResource ] ) {
651
619
addClientImport (
652
620
mod ,
653
- modRequest ,
621
+ modResource ,
654
622
clientComponentImports ,
655
623
importedIdentifiers ,
656
624
false
657
625
)
658
626
}
659
627
return
660
628
}
661
- visited . add ( modRequest )
629
+ visited . add ( modResource )
662
630
663
- const actions = getActions ( mod )
631
+ const actions = getActionsFromBuildInfo ( mod )
664
632
if ( actions ) {
665
- actionImports . push ( [ modRequest , actions ] )
633
+ actionImports . push ( [ modResource , actions ] )
666
634
}
667
635
668
636
const webpackRuntime = this . isEdgeServer
@@ -681,14 +649,14 @@ export class FlightClientEntryPlugin {
681
649
if ( unused ) return
682
650
}
683
651
684
- CSSImports . add ( modRequest )
652
+ CSSImports . add ( modResource )
685
653
} else if ( isClientComponentEntryModule ( mod ) ) {
686
- if ( ! clientComponentImports [ modRequest ] ) {
687
- clientComponentImports [ modRequest ] = new Set ( )
654
+ if ( ! clientComponentImports [ modResource ] ) {
655
+ clientComponentImports [ modResource ] = new Set ( )
688
656
}
689
657
addClientImport (
690
658
mod ,
691
- modRequest ,
659
+ modResource ,
692
660
clientComponentImports ,
693
661
importedIdentifiers ,
694
662
true
@@ -700,7 +668,6 @@ export class FlightClientEntryPlugin {
700
668
getModuleReferencesInOrder ( mod , compilation . moduleGraph ) . forEach (
701
669
( connection : any ) => {
702
670
let dependencyIds : string [ ] = [ ]
703
- const depModule = connection . resolvedModule
704
671
705
672
// `ids` are the identifiers that are imported from the dependency,
706
673
// if it's present, it's an array of strings.
@@ -710,7 +677,7 @@ export class FlightClientEntryPlugin {
710
677
dependencyIds = [ '*' ]
711
678
}
712
679
713
- filterClientComponents ( depModule , dependencyIds )
680
+ filterClientComponents ( connection . resolvedModule , dependencyIds )
714
681
}
715
682
)
716
683
}
@@ -1029,7 +996,7 @@ function addClientImport(
1029
996
modRequest : string ,
1030
997
clientComponentImports : ClientComponentImports ,
1031
998
importedIdentifiers : string [ ] ,
1032
- isFirstImport : boolean
999
+ isFirstVisitModule : boolean
1033
1000
) {
1034
1001
const clientEntryType = getModuleBuildInfo ( mod ) . rsc ?. clientEntryType
1035
1002
const isCjsModule = clientEntryType === 'cjs'
@@ -1044,7 +1011,7 @@ function addClientImport(
1044
1011
// If there's collected import path with named import identifiers,
1045
1012
// or there's nothing in collected imports are empty.
1046
1013
// we should include the whole module.
1047
- if ( ! isFirstImport && [ ...clientImportsSet ] [ 0 ] !== '*' ) {
1014
+ if ( ! isFirstVisitModule && [ ...clientImportsSet ] [ 0 ] !== '*' ) {
1048
1015
clientComponentImports [ modRequest ] = new Set ( [ '*' ] )
1049
1016
}
1050
1017
} else {
@@ -1069,3 +1036,26 @@ function addClientImport(
1069
1036
}
1070
1037
}
1071
1038
}
1039
+
1040
+ function getModuleResource ( mod : webpack . NormalModule ) : string {
1041
+ const modPath : string = mod . resourceResolveData ?. path || ''
1042
+ const modQuery = mod . resourceResolveData ?. query || ''
1043
+ // We have to always use the resolved request here to make sure the
1044
+ // server and client are using the same module path (required by RSC), as
1045
+ // the server compiler and client compiler have different resolve configs.
1046
+ let modResource : string = modPath + modQuery
1047
+
1048
+ // Context modules don't have a resource path, we use the identifier instead.
1049
+ if ( mod . constructor . name === 'ContextModule' ) {
1050
+ modResource = mod . identifier ( )
1051
+ }
1052
+
1053
+ // For the barrel optimization, we need to use the match resource instead
1054
+ // because there will be 2 modules for the same file (same resource path)
1055
+ // but they're different modules and can't be deduped via `visitedModule`.
1056
+ // The first module is a virtual re-export module created by the loader.
1057
+ if ( mod . matchResource ?. startsWith ( BARREL_OPTIMIZATION_PREFIX ) ) {
1058
+ modResource = mod . matchResource + ':' + modResource
1059
+ }
1060
+ return modResource
1061
+ }
0 commit comments