Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
AbanoubGhadban committed Jul 30, 2024
1 parent 2146f52 commit 1c026a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
27 changes: 15 additions & 12 deletions lib/react_on_rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions node_package/src/ReactOnRailsRSC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit 1c026a7

Please sign in to comment.