@@ -289,22 +289,28 @@ class CssLoadingRuntimeModule extends RuntimeModule {
289289 // collect it; never reject on a missing file
290290 const readCssFromDisk =
291291 withoutDocument || isNeutralPlatform
292- ? `Promise.all([import('fs'), import('url')]).then(${ runtimeTemplate . basicFunction (
293- "[{ readFile }, { URL }]" ,
294- [
295- `readFile(${ runtimeTemplate . importMetaUrl ( "url" ) } , 'utf8', ${ runtimeTemplate . basicFunction (
296- "err, content" ,
297- [
298- `if (!err) ${ runtimeTemplate . cssServerStyleRegistry ( ) } ["chunk-" + chunkId] = content;` ,
299- "loadingEnded({ type: 'load' });"
300- ]
301- ) } );`
302- ]
303- // No fs to import, or a url `readFile` rejects on sight (a CDN public
304- // path): nothing to collect, which is what a missing file already means.
305- ) } ).catch(${ runtimeTemplate . expressionFunction (
306- "loadingEnded({ type: 'load' })"
307- ) } );`
292+ ? Template . asString ( [
293+ `${ cst } registry = ${ runtimeTemplate . cssServerStyleRegistry ( ) } , key = "chunk-" + chunkId;` ,
294+ // Reserve request order before I/O without clearing another runtime's styles;
295+ // `||` only rewrites "" with "", so it matches an `undefined` check.
296+ `${ runtimeTemplate . assignOr ( "registry[key]" , '""' ) } ;` ,
297+ `Promise.all([import('fs'), import('url')]).then(${ runtimeTemplate . basicFunction (
298+ "[{ readFile }, { URL }]" ,
299+ [
300+ `readFile(${ runtimeTemplate . importMetaUrl ( "url" ) } , 'utf8', ${ runtimeTemplate . basicFunction (
301+ "err, content" ,
302+ [
303+ "if (!err) registry[key] = content;" ,
304+ "loadingEnded({ type: 'load' });"
305+ ]
306+ ) } );`
307+ ]
308+ // No fs to import, or a url `readFile` rejects on sight (a CDN public
309+ // path): nothing to collect, which is what a missing file already means.
310+ ) } ).catch(${ runtimeTemplate . expressionFunction (
311+ "loadingEnded({ type: 'load' })"
312+ ) } );`
313+ ] )
308314 : "" ;
309315 const installedChunksObject = `{\n${ Template . indent (
310316 Array . from ( initialChunkIds , ( id ) => `${ JSON . stringify ( id ) } : 0` ) . join (
0 commit comments