@@ -2,12 +2,12 @@ import type { ReactElement } from 'react';
22// @ts -expect-error will define this module types later
33import { renderToReadableStream } from 'react-server-dom-webpack/server.edge' ;
44import { PassThrough } from 'stream' ;
5+ import fs from 'fs' ;
56
67import { RenderParams } from './types' ;
78import ComponentRegistry from './ComponentRegistry' ;
89import createReactOutput from './createReactOutput' ;
910import { isPromise , isServerRenderHash } from './isServerRenderResult' ;
10- import handleError from './handleError' ;
1111import ReactOnRails from './ReactOnRails' ;
1212
1313( async ( ) => {
@@ -26,6 +26,16 @@ const stringToStream = (str: string) => {
2626 return stream ;
2727} ;
2828
29+ const getBundleConfig = ( ) => {
30+ const bundleConfig = JSON . parse ( fs . readFileSync ( './public/webpack/development/react-client-manifest.json' , 'utf8' ) ) ;
31+ // remove file:// from keys
32+ const newBundleConfig : { [ key : string ] : any } = { } ;
33+ for ( const [ key , value ] of Object . entries ( bundleConfig ) ) {
34+ newBundleConfig [ key . replace ( 'file://' , '' ) ] = value ;
35+ }
36+ return newBundleConfig ;
37+ }
38+
2939ReactOnRails . serverRenderRSCReactComponent = ( options : RenderParams ) => {
3040 const { name, domNodeId, trace, props, railsContext, throwJsErrors } = options ;
3141
@@ -52,7 +62,7 @@ See https://github.com/shakacode/react_on_rails#renderer-functions`);
5262 }
5363
5464 renderResult = new PassThrough ( ) ;
55- const streamReader = renderToReadableStream ( reactRenderingResult as ReactElement ) . getReader ( ) ;
65+ const streamReader = renderToReadableStream ( reactRenderingResult , getBundleConfig ( ) ) . getReader ( ) ;
5666 const processStream = async ( ) => {
5767 const { done, value } = await streamReader . read ( ) ;
5868 if ( done ) {
0 commit comments