@@ -134,6 +134,7 @@ export default (new Packager({
134134 'react-client' ,
135135 ) ;
136136 let React = loadModule ( 'react' , __filename , 'react-client' ) ;
137+ let ReactDOM = loadModule ( 'react' , __filename , 'react-server' ) ;
137138 let { createFromReadableStream} = loadModule (
138139 'react-server-dom-parcel/client.edge' ,
139140 __filename ,
@@ -153,33 +154,16 @@ export default (new Packager({
153154 } ,
154155 } ;
155156
156- let resources = [ ] ;
157157 let bootstrapModules = [ ] ;
158158 let entry ;
159- for ( let b of bundleGraph . getReferencedBundles ( bundle , {
159+ let referencedBundles = bundleGraph . getReferencedBundles ( bundle , {
160160 includeInline : false ,
161161 includeIsolated : false ,
162- } ) ) {
163- if ( b . type === 'css' ) {
164- resources . push (
165- React . createElement ( 'link' , {
166- key : b . id ,
167- rel : 'stylesheet' ,
168- href : urlJoin ( b . target . publicUrl , b . name ) ,
169- precedence : 'default' ,
170- } ) ,
171- ) ;
172- } else if ( b . type === 'js' && b . env . isBrowser ( ) ) {
173- bootstrapModules . push ( urlJoin ( b . target . publicUrl , b . name ) ) ;
174- resources . push (
175- React . createElement ( 'script' , {
176- key : b . id ,
177- type : 'module' ,
178- async : true ,
179- src : urlJoin ( b . target . publicUrl , b . name ) ,
180- } ) ,
181- ) ;
162+ } ) ;
182163
164+ for ( let b of referencedBundles ) {
165+ if ( b . type === 'js' && b . env . isBrowser ( ) ) {
166+ bootstrapModules . push ( urlJoin ( b . target . publicUrl , b . name ) ) ;
183167 if ( ! entry ) {
184168 b . traverseAssets ( ( a , ctx , actions ) => {
185169 if (
@@ -194,8 +178,40 @@ export default (new Packager({
194178 }
195179 }
196180
181+ function Resources ( ) {
182+ let resources = [ ] ;
183+ for ( let b of referencedBundles ) {
184+ if ( b . type === 'css' ) {
185+ let href = urlJoin ( b . target . publicUrl , b . name ) ;
186+
187+ // Add preload hint so we start loading the stylesheet as soon
188+ // as the RSC payload loads, without waiting for the component to mount.
189+ ReactDOM . preload ( href , { as : 'style' } ) ;
190+ resources . push (
191+ React . createElement ( 'link' , {
192+ key : b . id ,
193+ rel : 'stylesheet' ,
194+ href,
195+ precedence : 'default' ,
196+ } ) ,
197+ ) ;
198+ } else if ( b . type === 'js' && b . env . isBrowser ( ) ) {
199+ resources . push (
200+ React . createElement ( 'script' , {
201+ key : b . id ,
202+ type : 'module' ,
203+ async : true ,
204+ src : urlJoin ( b . target . publicUrl , b . name ) ,
205+ } ) ,
206+ ) ;
207+ }
208+ }
209+
210+ return resources ;
211+ }
212+
197213 let stream = renderToReadableStream ( [
198- ... resources ,
214+ React . createElement ( Resources , { key : ' resources' } ) ,
199215 React . createElement ( Component , props ) ,
200216 ] ) ;
201217 let [ s1 , renderStream ] = stream . tee ( ) ;
@@ -302,8 +318,12 @@ async function loadBundleUncached(
302318 let packagedBundle = await nullthrows (
303319 packagingBundles . get ( entryBundle ) ,
304320 ) ;
321+ let inlineType = nullthrows ( entryBundle . getMainEntry ( ) ) . meta
322+ . inlineType ;
305323 let contents = await blobToString ( packagedBundle . contents ) ;
306- contents = `module.exports = ${ contents } ` ;
324+ contents = `module.exports = ${
325+ inlineType === 'string' ? JSON . stringify ( contents ) : contents
326+ } `;
307327 return [
308328 [
309329 entryBundle . id ,
@@ -667,6 +687,7 @@ function runModule(
667687
668688function getCacheKey ( asset : Asset ) {
669689 return (
690+ ( asset . pipeline || '' ) +
670691 asset . filePath +
671692 '#' +
672693 asset . env . context +
0 commit comments