@@ -139,7 +139,7 @@ describe('appendUniqueAssets', () => {
139139 test ( 'returns original target array when nothing new is appended' , ( ) => {
140140 const target = [
141141 {
142- tag : 'link' ,
142+ tag : 'link' as const ,
143143 attrs : {
144144 rel : 'stylesheet' ,
145145 href : '/assets/a.css' ,
@@ -151,7 +151,7 @@ describe('appendUniqueAssets', () => {
151151 expect (
152152 appendUniqueAssets ( target , [
153153 {
154- tag : 'link' ,
154+ tag : 'link' as const ,
155155 attrs : {
156156 rel : 'stylesheet' ,
157157 href : '/assets/a.css' ,
@@ -221,20 +221,18 @@ describe('collectDynamicImportCss', () => {
221221 ] ) ,
222222 )
223223
224- expect ( Array . from ( dynamicCss ) . sort ( ) ) . toEqual ( [ 'lazy.css' , 'shared.css' ] )
225- expect ( dynamicCss . has ( 'route.css' ) ) . toBe ( false )
224+ expect ( Array . from ( dynamicCss ) ) . toEqual ( [ ] )
226225 } )
227226
228- test ( 'collects css reachable both statically and dynamically from different entry points' , ( ) => {
229- // shared.css is statically imported by routeA, and dynamically imported by routeB
227+ test ( 'ignores CSS shared only across router-managed routes' , ( ) => {
230228 const routeA = makeChunk ( {
231229 fileName : 'routeA.js' ,
232230 imports : [ 'shared.js' ] ,
233231 moduleIds : [ '/routes/a.tsx?tsr-split=component' ] ,
234232 } )
235233 const routeB = makeChunk ( {
236234 fileName : 'routeB.js' ,
237- dynamicImports : [ 'shared.js' ] ,
235+ imports : [ 'shared.js' ] ,
238236 moduleIds : [ '/routes/b.tsx?tsr-split=component' ] ,
239237 } )
240238 const sharedChunk = makeChunk ( {
@@ -251,7 +249,40 @@ describe('collectDynamicImportCss', () => {
251249 ] ) ,
252250 )
253251
254- // shared.css is reachable via dynamic import from routeB, so it should be in the set
252+ expect ( dynamicCss . has ( 'shared.css' ) ) . toBe ( false )
253+ } )
254+
255+ test ( 'collects css reachable through both router-managed and non-route dynamic imports' , ( ) => {
256+ const entryChunk = makeChunk ( {
257+ fileName : 'entry.js' ,
258+ isEntry : true ,
259+ dynamicImports : [ 'lazy.js' ] ,
260+ } )
261+ const routeChunk = makeChunk ( {
262+ fileName : 'route.js' ,
263+ imports : [ 'shared.js' ] ,
264+ moduleIds : [ '/routes/home.tsx?tsr-split=component' ] ,
265+ } )
266+ const lazyChunk = makeChunk ( {
267+ fileName : 'lazy.js' ,
268+ imports : [ 'shared.js' ] ,
269+ } )
270+ const sharedChunk = makeChunk ( {
271+ fileName : 'shared.js' ,
272+ importedCss : [ 'shared.css' ] ,
273+ } )
274+
275+ const dynamicCss = collectDynamicImportCss (
276+ new Set ( [ routeChunk ] ) ,
277+ new Map ( [
278+ [ 'entry.js' , entryChunk ] ,
279+ [ 'route.js' , routeChunk ] ,
280+ [ 'lazy.js' , lazyChunk ] ,
281+ [ 'shared.js' , sharedChunk ] ,
282+ ] ) ,
283+ entryChunk ,
284+ )
285+
255286 expect ( dynamicCss . has ( 'shared.css' ) ) . toBe ( true )
256287 } )
257288} )
@@ -274,7 +305,7 @@ describe('createManifestAssetResolvers + createChunkCssAssetCollector', () => {
274305
275306 const resolvers = createManifestAssetResolvers ( {
276307 basePath : '/assets' ,
277- dynamicCssFiles : new Set ( [ 'shared.css' ] ) ,
308+ hashedCssFiles : new Set ( [ 'shared.css' ] ) ,
278309 } )
279310 const cssAssetCollector = createChunkCssAssetCollector ( {
280311 chunksByFileName,
@@ -343,7 +374,7 @@ describe('createChunkCssAssetCollector', () => {
343374} )
344375
345376describe ( 'buildStartManifest' , ( ) => {
346- test ( 'builds route and root assets with dynamic css hash handling ' , ( ) => {
377+ test ( 'hashes css shared by route chunks and nested non-route dynamic imports ' , ( ) => {
347378 const entryChunk = makeChunk ( {
348379 fileName : 'entry.js' ,
349380 isEntry : true ,
@@ -410,6 +441,114 @@ describe('buildStartManifest', () => {
410441 '/assets/route-lazy.js' ,
411442 ] )
412443 } )
444+
445+ test ( 'keeps entry-owned css unsuffixed when shared only with route chunks' , ( ) => {
446+ const entryChunk = makeChunk ( {
447+ fileName : 'entry.js' ,
448+ isEntry : true ,
449+ imports : [ 'shared.js' ] ,
450+ dynamicImports : [ 'about.js' ] ,
451+ } )
452+ const sharedChunk = makeChunk ( {
453+ fileName : 'shared.js' ,
454+ importedCss : [ 'main.css' ] ,
455+ } )
456+ const aboutChunk = makeChunk ( {
457+ fileName : 'about.js' ,
458+ imports : [ 'shared.js' ] ,
459+ importedCss : [ 'about.css' ] ,
460+ moduleIds : [ '/routes/about.tsx?tsr-split=component' ] ,
461+ } )
462+
463+ const manifest = buildStartManifest ( {
464+ clientBundle : {
465+ 'entry.js' : entryChunk ,
466+ 'shared.js' : sharedChunk ,
467+ 'about.js' : aboutChunk ,
468+ } ,
469+ routeTreeRoutes : {
470+ __root__ : { children : [ '/about' ] } as any ,
471+ '/about' : { filePath : '/routes/about.tsx' } ,
472+ } ,
473+ basePath : '/assets' ,
474+ } )
475+
476+ expect ( manifest . routes . __root__ ! . assets ) . toEqual ( [
477+ {
478+ tag : 'link' ,
479+ attrs : {
480+ rel : 'stylesheet' ,
481+ href : '/assets/main.css' ,
482+ type : 'text/css' ,
483+ } ,
484+ } ,
485+ ] )
486+
487+ expect ( manifest . routes [ '/about' ] ! . assets ) . toEqual ( [
488+ {
489+ tag : 'link' ,
490+ attrs : {
491+ rel : 'stylesheet' ,
492+ href : '/assets/about.css' ,
493+ type : 'text/css' ,
494+ } ,
495+ } ,
496+ {
497+ tag : 'link' ,
498+ attrs : {
499+ rel : 'stylesheet' ,
500+ href : '/assets/main.css' ,
501+ type : 'text/css' ,
502+ } ,
503+ } ,
504+ ] )
505+ } )
506+
507+ test ( 'adds hash only when css is shared by router-managed and non-route dynamic imports' , ( ) => {
508+ const entryChunk = makeChunk ( {
509+ fileName : 'entry.js' ,
510+ isEntry : true ,
511+ dynamicImports : [ 'global-lazy.js' ] ,
512+ } )
513+ const routeChunk = makeChunk ( {
514+ fileName : 'route.js' ,
515+ imports : [ 'shared.js' ] ,
516+ moduleIds : [ '/routes/about.tsx?tsr-split=component' ] ,
517+ } )
518+ const sharedChunk = makeChunk ( {
519+ fileName : 'shared.js' ,
520+ importedCss : [ 'shared.css' ] ,
521+ } )
522+ const globalLazyChunk = makeChunk ( {
523+ fileName : 'global-lazy.js' ,
524+ imports : [ 'shared.js' ] ,
525+ } )
526+
527+ const manifest = buildStartManifest ( {
528+ clientBundle : {
529+ 'entry.js' : entryChunk ,
530+ 'route.js' : routeChunk ,
531+ 'shared.js' : sharedChunk ,
532+ 'global-lazy.js' : globalLazyChunk ,
533+ } ,
534+ routeTreeRoutes : {
535+ __root__ : { children : [ '/about' ] } as any ,
536+ '/about' : { filePath : '/routes/about.tsx' } ,
537+ } ,
538+ basePath : '/assets' ,
539+ } )
540+
541+ expect ( manifest . routes [ '/about' ] ! . assets ) . toEqual ( [
542+ {
543+ tag : 'link' ,
544+ attrs : {
545+ rel : 'stylesheet' ,
546+ href : '/assets/shared.css#' ,
547+ type : 'text/css' ,
548+ } ,
549+ } ,
550+ ] )
551+ } )
413552} )
414553
415554describe ( 'dedupeNestedRoutePreloads' , ( ) => {
@@ -642,8 +781,8 @@ describe('entry chunk dynamic imports must be scanned for dynamic CSS', () => {
642781 basePath : '/assets' ,
643782 } )
644783
645- // global-lazy.css is reachable via dynamic import from entry chunk,
646- // so the route 's reference to it should have the # suffix
784+ // global-lazy.css is reachable through both the router-managed route
785+ // and the entry chunk 's non-route dynamic import, so it should have #
647786 const homeAssets = manifest . routes [ '/home' ] ! . assets !
648787 const globalLazyCss = homeAssets . find ( ( a : any ) =>
649788 a . attrs . href . includes ( 'global-lazy.css' ) ,
0 commit comments