@@ -237,7 +237,7 @@ const emitRscFiles = async (
237
237
} ;
238
238
const rscFileSet = new Set < string > ( ) ; // XXX could be implemented better
239
239
await Promise . all (
240
- Object . entries ( buildConfig ) . map ( async ( [ , { elements } ] ) => {
240
+ Object . entries ( buildConfig ) . map ( async ( [ , { elements, ctx } ] ) => {
241
241
for ( const [ rscId , props ] of elements || [ ] ) {
242
242
// FIXME we blindly expect JSON.stringify usage is deterministic
243
243
const serializedProps = JSON . stringify ( props ) ;
@@ -253,10 +253,11 @@ const emitRscFiles = async (
253
253
if ( ! rscFileSet . has ( destFile ) ) {
254
254
rscFileSet . add ( destFile ) ;
255
255
fs . mkdirSync ( path . dirname ( destFile ) , { recursive : true } ) ;
256
- const pipeable = renderRSC (
256
+ const [ pipeable ] = await renderRSC (
257
257
{ rscId, props } ,
258
258
{
259
259
command : "build" ,
260
+ ctx,
260
261
moduleIdCallback : ( id ) =>
261
262
addClientModule ( rscId , serializedProps , id ) ,
262
263
}
@@ -277,15 +278,19 @@ const emitRscFiles = async (
277
278
const renderHtml = async (
278
279
config : Awaited < ReturnType < typeof resolveConfig > > ,
279
280
pathStr : string ,
280
- htmlStr : string
281
+ htmlStr : string ,
282
+ ctx : unknown
281
283
) => {
282
284
const ssrConfig = await getSsrConfigRSC ( pathStr , "build" ) ;
283
285
if ( ! ssrConfig ) {
284
286
return null ;
285
287
}
286
288
const { splitHTML, getFallback } = config . framework . ssr ;
287
289
const [ rscId , props ] = ssrConfig . element ;
288
- const pipeable = renderRSC ( { rscId, props } , { command : "build" } ) ;
290
+ const [ pipeable ] = await renderRSC (
291
+ { rscId, props } ,
292
+ { command : "build" , ctx }
293
+ ) ;
289
294
return renderHtmlToReadable ( htmlStr , pipeable , splitHTML , getFallback ) ;
290
295
} ;
291
296
@@ -306,7 +311,7 @@ const emitHtmlFiles = async (
306
311
} ) ;
307
312
const htmlFiles = await Promise . all (
308
313
Object . entries ( buildConfig ) . map (
309
- async ( [ pathStr , { elements, customCode, skipSsr } ] ) => {
314
+ async ( [ pathStr , { elements, customCode, ctx , skipSsr } ] ) => {
310
315
const destFile = path . join (
311
316
config . root ,
312
317
config . framework . distDir ,
@@ -346,7 +351,7 @@ const emitHtmlFiles = async (
346
351
data = data . replace ( / < \/ h e a d > / , `<script>${ code } </script></head>` ) ;
347
352
}
348
353
const htmlReadable =
349
- ! skipSsr && ( await renderHtml ( config , pathStr , data ) ) ;
354
+ ! skipSsr && ( await renderHtml ( config , pathStr , data , ctx ) ) ;
350
355
if ( htmlReadable ) {
351
356
await new Promise < void > ( ( resolve , reject ) => {
352
357
const stream = fs . createWriteStream ( destFile ) ;
0 commit comments