diff --git a/lib/react_on_rails/helper.rb b/lib/react_on_rails/helper.rb index 7e0a2dbf04..203c28bcb3 100644 --- a/lib/react_on_rails/helper.rb +++ b/lib/react_on_rails/helper.rb @@ -92,12 +92,14 @@ def react_component(component_name, options = {}) end def rsc_react_component(component_name, options = {}) - res = internal_rsc_react_component(component_name, options) - s = "" - res.each_chunk do |chunk| - s += chunk + rendering_fiber = Fiber.new do + res = internal_rsc_react_component(component_name, options) + res.each_chunk do |chunk| + Fiber.yield chunk + end + Fiber.yield nil end - s + rendering_fiber end def stream_react_component(component_name, options = {}) @@ -348,13 +350,14 @@ def load_pack_for_generated_component(react_component_name, render_options) return unless render_options.auto_load_bundle ReactOnRails::PackerUtils.raise_nested_entries_disabled unless ReactOnRails::PackerUtils.nested_entries? - if Rails.env.development? - is_component_pack_present = File.exist?(generated_components_pack_path(react_component_name)) - raise_missing_autoloaded_bundle(react_component_name) unless is_component_pack_present - end - append_javascript_pack_tag("generated/#{react_component_name}", - defer: ReactOnRails.configuration.defer_generated_component_packs) - append_stylesheet_pack_tag("generated/#{react_component_name}") + append_javascript_pack_tag("client-bundle") + # if Rails.env.development? + # is_component_pack_present = File.exist?(generated_components_pack_path(react_component_name)) + # raise_missing_autoloaded_bundle(react_component_name) unless is_component_pack_present + # end + # append_javascript_pack_tag("generated/#{react_component_name}", + # defer: ReactOnRails.configuration.defer_generated_component_packs) + # append_stylesheet_pack_tag("generated/#{react_component_name}") end # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity diff --git a/node_package/src/ReactOnRailsRSC.ts b/node_package/src/ReactOnRailsRSC.ts index 1d1de30ae7..cd265b5660 100644 --- a/node_package/src/ReactOnRailsRSC.ts +++ b/node_package/src/ReactOnRailsRSC.ts @@ -2,12 +2,12 @@ import type { ReactElement } from 'react'; // @ts-expect-error will define this module types later import { renderToReadableStream } from 'react-server-dom-webpack/server.edge'; import { PassThrough } from 'stream'; +import fs from 'fs'; import { RenderParams } from './types'; import ComponentRegistry from './ComponentRegistry'; import createReactOutput from './createReactOutput'; import { isPromise, isServerRenderHash } from './isServerRenderResult'; -import handleError from './handleError'; import ReactOnRails from './ReactOnRails'; (async () => { @@ -26,6 +26,16 @@ const stringToStream = (str: string) => { return stream; }; +const getBundleConfig = () => { + const bundleConfig = JSON.parse(fs.readFileSync('./public/webpack/development/react-client-manifest.json', 'utf8')); + // remove file:// from keys + const newBundleConfig: { [key: string]: any } = {}; + for (const [key, value] of Object.entries(bundleConfig)) { + newBundleConfig[key.replace('file://', '')] = value; + } + return newBundleConfig; +} + ReactOnRails.serverRenderRSCReactComponent = (options: RenderParams) => { const { name, domNodeId, trace, props, railsContext, throwJsErrors } = options; @@ -52,7 +62,7 @@ See https://github.com/shakacode/react_on_rails#renderer-functions`); } renderResult = new PassThrough(); - const streamReader = renderToReadableStream(reactRenderingResult as ReactElement).getReader(); + const streamReader = renderToReadableStream(reactRenderingResult, getBundleConfig()).getReader(); const processStream = async () => { const { done, value } = await streamReader.read(); if (done) {