Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for RSC #1644

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

AbanoubGhadban
Copy link
Collaborator

@AbanoubGhadban AbanoubGhadban commented Jul 22, 2024

Summary

RSC_in_RORP.mp4

Remove this paragraph and provide a general description of the code changes in your pull
request... were there any bugs you had fixed? If so, mention them. If
these bugs have open GitHub issues, be sure to tag them here as well,
to keep the conversation linked together.

Pull Request checklist

Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by ~.

  • Add/update test to cover these changes
  • Update documentation
  • Update CHANGELOG file
    Add the CHANGELOG entry at the top of the file.

Other Information

Remove this paragraph and mention any other important and relevant information such as benchmarks.


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Enhanced server-side rendering capabilities for React components, including support for streaming and React Server Components.
    • Introduced new methods for checking rendering options in the render settings.
    • Added new JavaScript execution capabilities for streaming.
    • Improved module exports for better compatibility across JavaScript environments.
  • Bug Fixes

    • Improved efficiency by reducing redundant context rendering.
  • Documentation

    • Updated the changelog for better organization and clarity on migration instructions and support offerings.
  • Chores

    • Updated various dependencies to their latest versions for improved compatibility and performance.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates to the react-on-rails project significantly enhance server-side rendering capabilities for React components. New streaming methods have been introduced, allowing for asynchronous rendering and improved processing of JavaScript bundles. These modifications accommodate modern features like React Server Components and ensure compatibility with the latest package dependencies, thereby optimizing performance and usability for developers.

Changes

Files Change Summary
lib/react_on_rails/helper.rb Added methods for RSC and streaming React components; modified loading context for components.
lib/react_on_rails/react_component/render_options.rb Introduced methods to access :stream? and :rsc? options for easier querying.
lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb Added method for streaming JavaScript execution, enhancing modularity.
lib/react_on_rails/utils.rb Redefined bundle path methods for improved flexibility; added new method for RSC bundle paths.
node_package/src/ReactOnRails.ts Enhanced server rendering with new methods for handling streams.
node_package/src/ReactOnRailsRSC.ts Introduced server-side rendering functionality specific to React Server Components.
node_package/src/serverRenderReactComponent.ts Updated rendering logic to utilize streams, improving performance.
node_package/src/types/index.ts Added types for new server rendering methods in the ReactOnRails interface.
package.json Added module exports for better interoperability; updated dependencies to newer versions.
spec/dummy/config/webpack/alias.js Added alias for stream to use stream-browserify, enhancing compatibility.
spec/dummy/config/webpack/webpackConfig.js Modified client config to resolve stream to stream-browserify.
jest.config.js Added setupFiles property for initial Jest setup configuration.
node_package/tests/ReactOnRails.test.js Updated test setup to manipulate DOM elements directly for clearer output validation.
node_package/tests/jest.setup.js Introduced polyfills for TextEncoder and TextDecoder in Jest testing environment.
.gitignore Added entry to ignore .idea/ directory for better version control.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant ReactComponent
    participant JSExecutor
    
    User->>Server: Request for React component
    Server->>JSExecutor: Execute JS and render component
    JSExecutor->>ReactComponent: Render to stream
    ReactComponent->>JSExecutor: Return streamed output
    JSExecutor-->>Server: Deliver streamed content
    Server-->>User: Send back rendered content
Loading

🐰 In the meadow, I hop with delight,
New features sprout, oh what a sight!
Streaming and rendering, all in a flow,
React's magic makes our app glow!
With bundles and paths so clever and bright,
Let's celebrate changes, oh what a night! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (4)
spec/dummy/config/webpack/alias.js (1)

7-7: Add a comment explaining the alias mapping.

Adding a comment to explain why the stream alias is needed would improve maintainability.

+      // Alias for stream module to ensure compatibility with browser environments
       stream: 'stream-browserify'
spec/dummy/config/webpack/webpackConfig.js (1)

7-7: Add a comment explaining the fallback configuration.

Adding a comment to explain why the stream fallback is needed would improve maintainability.

+  // Fallback configuration for stream module to ensure compatibility with browser environments
   clientConfig.resolve.fallback = { stream: require.resolve('stream-browserify') };
node_package/src/ReactOnRailsRSC.ts (2)

13-20: Handle the absence of AsyncLocalStorage more robustly.

Consider providing more details in the log message or handling the absence of AsyncLocalStorage in a way that informs the user of potential limitations.

-    console.log('AsyncLocalStorage not found');
+    console.warn('AsyncLocalStorage not found. Some features may not work as expected.');

29-76: Ensure comprehensive test coverage for serverRenderRSCReactComponent.

Given the complexity of this function, ensure that it is comprehensively tested, especially for error handling and edge cases.

  • No references to serverRenderRSCReactComponent were found in the existing test files.
Analysis chain

Ensure comprehensive test coverage for serverRenderRSCReactComponent.

Given the complexity of this function, ensure that it is comprehensively tested, especially for error handling and edge cases.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if comprehensive tests are provided for `serverRenderRSCReactComponent`.

# Test: Search for test cases related to `serverRenderRSCReactComponent`. Expect: Comprehensive test cases.
rg --type javascript --type typescript 'serverRenderRSCReactComponent'

Length of output: 105


Script:

#!/bin/bash
# Description: Verify if comprehensive tests are provided for `serverRenderRSCReactComponent`.

# Test: Search for test cases related to `serverRenderRSCReactComponent`. Expect: Comprehensive test cases.
rg --type js --type ts 'serverRenderRSCReactComponent'

Length of output: 488


Script:

#!/bin/bash
# Description: Verify if comprehensive tests are provided for `serverRenderRSCReactComponent`.

# Step 1: Find all test files in the repository.
test_files=$(fd --type f --extension js --extension ts --glob '*test*')

# Step 2: Search for references to `serverRenderRSCReactComponent` in the identified test files.
if [ -n "$test_files" ]; then
  rg 'serverRenderRSCReactComponent' $test_files
else
  echo "No test files found."
fi

Length of output: 1289

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7f01c2a and 4e3ad5b.

Files ignored due to path filters (2)
  • Gemfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (11)
  • lib/react_on_rails/helper.rb (4 hunks)
  • lib/react_on_rails/react_component/render_options.rb (1 hunks)
  • lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb (1 hunks)
  • lib/react_on_rails/utils.rb (2 hunks)
  • node_package/src/ReactOnRails.ts (2 hunks)
  • node_package/src/ReactOnRailsRSC.ts (1 hunks)
  • node_package/src/serverRenderReactComponent.ts (4 hunks)
  • node_package/src/types/index.ts (2 hunks)
  • package.json (3 hunks)
  • spec/dummy/config/webpack/alias.js (1 hunks)
  • spec/dummy/config/webpack/webpackConfig.js (1 hunks)
Additional comments not posted (26)
node_package/src/ReactOnRailsRSC.ts (3)

22-27: LGTM!

The stringToStream function is correctly implemented.


78-79: LGTM!

The export statements are correctly implemented.


1-4: Ensure type definitions are added for the modules.

The @ts-expect-error comments indicate that type definitions are pending. Ensure these are added to avoid type errors.

Verification successful

Ensure type definitions are added for the modules.

The @ts-expect-error comments indicate that type definitions are pending for the renderToReadableStream and PassThrough modules. Ensure these are added to avoid type errors.

  • node_package/src/ReactOnRailsRSC.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if type definitions for the modules are added or tracked in the codebase.

# Test: Search for type definition files or TODO comments. Expect: Type definitions or tracking comments.
rg --type typescript -A 2 '@ts-expect-error'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify if type definitions for the modules are added or tracked in the codebase.

# Test: Search for type definition files or TODO comments. Expect: Type definitions or tracking comments.
rg --type-add 'ts:*.ts' -A 2 '@ts-expect-error'

Length of output: 883

package.json (5)

23-23: LGTM!

Updating @types/react to ^18.2.0 ensures better type safety and compatibility with the latest React version.


24-24: LGTM!

Updating @types/react-dom to ^18.2.0 ensures better type safety and compatibility with the latest React version.


49-49: LGTM! Verify the usage of the new dependency.

Adding react-server-dom-webpack enhances server-side rendering capabilities.

However, ensure that the new dependency is correctly utilized in the codebase.

Verification successful

Verified Usage of react-server-dom-webpack

The react-server-dom-webpack dependency is correctly utilized in the codebase, specifically in node_package/src/ReactOnRailsRSC.ts.

  • node_package/src/ReactOnRailsRSC.ts: Import and usage of renderToReadableStream from react-server-dom-webpack/server.edge.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new dependency in the codebase.

# Test: Search for the usage of `react-server-dom-webpack`. Expect: Correct usage of the new dependency.
rg --type js -A 5 $'react-server-dom-webpack'

Length of output: 44


Script:

#!/bin/bash
# Description: Verify the usage of the new dependency in the codebase.

# Test: Search for the usage of `react-server-dom-webpack` in all file types.
rg -A 5 'react-server-dom-webpack'

# Test: Search for import statements that might alias `react-server-dom-webpack`.
rg -A 5 'import .* from .*react-server-dom-webpack'

Length of output: 1847


5-10: LGTM! Verify the usage of new entry points.

The addition of the exports field enhances module interoperability by specifying entry points for both server-side and default usage.

However, ensure that the new entry points are correctly utilized in the codebase.


47-48: LGTM! Verify compatibility with the rest of the codebase.

Updating react and react-dom to 18.3.0-canary-670811593-20240322 aligns with modern React practices but ensure compatibility with the rest of the codebase.

Verification successful

Verify compatibility with the rest of the codebase.

Updating react and react-dom to 18.3.0-canary-670811593-20240322 aligns with modern React practices but ensure compatibility with the rest of the codebase by checking for deprecated or breaking changes.


Verify compatibility with the rest of the codebase.

Updating react and react-dom to 18.3.0-canary-670811593-20240322 aligns with modern React practices but ensure compatibility with the rest of the codebase by conducting a comprehensive check.


LGTM! Verify compatibility with the rest of the codebase.

Updating react and react-dom to 18.3.0-canary-670811593-20240322 aligns with modern React practices. The search did not reveal any deprecated lifecycle methods or breaking changes. Ensure compatibility with the rest of the codebase by conducting manual verification if necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify compatibility with the rest of the codebase.

# Test: Search for the usage of `react` and `react-dom`. Expect: No compatibility issues.
rg --type js -A 5 $'react'
rg --type js -A 5 $'react-dom'

Length of output: 44790


Script:

#!/bin/bash
# Description: Verify compatibility with the rest of the codebase for deprecated or breaking changes.

# Test: Search for deprecated React lifecycle methods that might be affected by the update.
rg --type js -A 5 'componentWillMount|componentWillReceiveProps|componentWillUpdate'

# Test: Search for usage of ReactDOM methods that might have breaking changes.
rg --type js -A 5 'ReactDOM.render|ReactDOM.hydrate|ReactDOM.createPortal'

Length of output: 163


Script:

#!/bin/bash
# Description: Verify compatibility with the rest of the codebase for React components and ReactDOM usages.

# Test: Search for all React component definitions.
rg --type js -A 5 'React.Component|React.PureComponent|function\s+\w+\s*\('

# Test: Search for all ReactDOM usages.
rg --type js -A 5 'ReactDOM.render|ReactDOM.hydrate|ReactDOM.createRoot|ReactDOM.hydrateRoot'

Length of output: 10621

lib/react_on_rails/react_component/render_options.rb (2)

106-108: LGTM!

The stream? method provides a straightforward way to query the :stream? option.


110-112: LGTM!

The rsc? method provides a straightforward way to query the :rsc? option.

node_package/src/types/index.ts (2)

142-142: LGTM! Verify the implementation of the new method.

The serverRenderRSCReactComponent method enhances performance and user experience by enabling progressive rendering.

However, ensure that the new method is correctly implemented in the codebase.


141-141: LGTM! Verify the implementation of the new method.

The streamServerRenderedReactComponent method enhances performance and user experience by enabling progressive rendering.

However, ensure that the new method is correctly implemented in the codebase.

Verification successful

The streamServerRenderedReactComponent method is correctly implemented.

The method is defined in serverRenderReactComponent.ts and handles the streaming of server-rendered React components using ReactDOMServer.renderToPipeableStream. It also includes error handling to manage exceptions during rendering.

  • Implementation found in node_package/src/serverRenderReactComponent.ts from lines 209 to 249.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the new method in the codebase.

# Test: Search for the implementation of `streamServerRenderedReactComponent`. Expect: Correct implementation of the new method.
rg --type ts -A 5 $'streamServerRenderedReactComponent'

Length of output: 2064


Script:

#!/bin/bash
# Description: Extract the full implementation of the `streamServerRenderedReactComponent` method.

# Test: Retrieve the implementation details of `streamServerRenderedReactComponent`.
rg --type ts -A 20 $'export const streamServerRenderedReactComponent = (options: RenderParams) => {'

Length of output: 321


Script:

#!/bin/bash
# Description: Extract the full implementation of the `streamServerRenderedReactComponent` method.

# Test: Retrieve the implementation details of `streamServerRenderedReactComponent`.
rg --type ts -A 50 $'export const streamServerRenderedReactComponent = \\(options: RenderParams\\) => {'

Length of output: 327


Script:

#!/bin/bash
# Description: Extract the full implementation of the `streamServerRenderedReactComponent` method using ast-grep.

# Test: Retrieve the implementation details of `streamServerRenderedReactComponent`.
ast-grep --lang typescript --pattern $'export const streamServerRenderedReactComponent = (options: RenderParams) => {
  $$$
}'

Length of output: 3488

node_package/src/serverRenderReactComponent.ts (3)

1-2: Update import statements for React and PipeableStream.

The import of React and PipeableStream from react-dom/server aligns with the new stream-based rendering approach.


74-101: Implement stream-based rendering using renderToPipeableStream.

The new implementation uses renderToPipeableStream for stream-based rendering. This approach enhances performance and allows for asynchronous processing of the rendered output. Ensure that the stream is correctly handled and errors are properly managed.


209-249: Introduce streamServerRenderedReactComponent function.

The new function encapsulates the logic for rendering a React component into a stream. It checks for conditions and handles errors appropriately. This addition enhances the server-side rendering capabilities by supporting stream-based rendering.

lib/react_on_rails/utils.rb (3)

Line range hint 69-92:
Redefine bundle_js_file_path method.

The method now includes a new parameter bundle_name, allowing it to handle different bundle names dynamically. This change enhances the flexibility and robustness of the method.


96-110: Update server_bundle_js_file_path method.

The method now uses the new bundle_js_file_path method, aligning with the new structure for managing bundle paths. This update enhances maintainability and clarity.


112-117: Introduce rsc_bundle_js_file_path method.

The new method handles the RSC bundle path, following the same pattern as the server_bundle_js_file_path method. This addition improves the modularity and configurability of the code.

lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb (1)

95-99: Introduce exec_server_render_streaming_js method.

The new method handles JavaScript code execution in a streaming manner. It accepts three parameters: js_code, render_options, and an optional js_evaluator. This addition expands the capabilities of the module by allowing for streaming JavaScript execution.

node_package/src/ReactOnRails.ts (2)

245-251: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to streamServerRenderedReactComponent are correctly implemented.


253-260: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that the function serverRenderRSCReactComponent is not mistakenly invoked in the wrong context.

Verification successful

The function serverRenderRSCReactComponent is not mistakenly invoked in the wrong context.

  • The function is defined in node_package/src/ReactOnRails.ts and throws an error if invoked.
  • It is referenced in node_package/src/ReactOnRailsRSC.ts and node_package/src/types/index.ts, but no invocations were found outside these contexts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `serverRenderRSCReactComponent` are correctly implemented.

# Test: Search for the function usage. Expect: Correct implementation of the function calls.
rg --type ts -A 5 $'serverRenderRSCReactComponent'

Length of output: 1445


Script:

#!/bin/bash
# Description: Verify the context of the function usage in `node_package/src/ReactOnRailsRSC.ts` and `node_package/src/types/index.ts`.

# Search for the function usage in `node_package/src/ReactOnRailsRSC.ts` with more context lines.
rg --type ts -A 10 -B 10 $'serverRenderRSCReactComponent' node_package/src/ReactOnRailsRSC.ts

# Search for the function usage in `node_package/src/types/index.ts` with more context lines.
rg --type ts -A 10 -B 10 $'serverRenderRSCReactComponent' node_package/src/types/index.ts

Length of output: 1701


Script:

#!/bin/bash
# Description: Verify that `serverRenderRSCReactComponent` is not mistakenly invoked outside the intended context.

# Search for invocations of `serverRenderRSCReactComponent` across the codebase.
rg --type ts $'serverRenderRSCReactComponent('

Length of output: 158


Script:

#!/bin/bash
# Description: Verify that `serverRenderRSCReactComponent` is not mistakenly invoked outside the intended context.

# Search for invocations of `serverRenderRSCReactComponent` across the codebase with corrected regex pattern.
rg --type ts 'serverRenderRSCReactComponent\('

Length of output: 252

lib/react_on_rails/helper.rb (5)

480-484: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to internal_rsc_react_component are correctly implemented.


113-121: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to stream_react_component_async are correctly implemented.


103-111: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to stream_react_component are correctly implemented.

Verification successful

Verified: The function usage of stream_react_component is correctly implemented.

The only usage of stream_react_component is within the stream_react_component_async method, and it is used appropriately in an asynchronous context.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `stream_react_component` are correctly implemented.

# Test: Search for the function usage. Expect: Correct implementation of the function calls.
rg --type ruby -A 5 $'stream_react_component'

Length of output: 1048


Script:

#!/bin/bash
# Description: Verify all function calls to `stream_react_component` are correctly implemented across the entire codebase.

# Test: Search for the function usage. Expect: Correct implementation of the function calls.
rg --type ruby 'stream_react_component'

Length of output: 319


94-101: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to rsc_react_component are correctly implemented.


393-417: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to build_react_component_result_for_server_streamed_content are correctly implemented.

Verification successful

Verify the function call context in the codebase.

The function build_react_component_result_for_server_streamed_content is called within the same file where it is defined. Ensure that the parameters result[:result], result[:tag], and result[:render_options] are correctly defined and passed in the calling context.


Verify the function call context in the codebase.

The previous script failed due to a regex parse error. Let's correct the search pattern and re-run the script to verify the context of the function call to build_react_component_result_for_server_streamed_content.


Verify the return value of the internal_react_component method.

The function call to build_react_component_result_for_server_streamed_content is found within the stream_react_component method. We need to verify the internal_react_component method to ensure that it returns a hash with the keys :result, :tag, and :render_options.


Verify the complete implementation of the internal_react_component method.

We need to see the full implementation of the internal_react_component method to confirm if it returns a hash with the keys :result, :tag, and :render_options.


Function usage verified successfully.

The function build_react_component_result_for_server_streamed_content is correctly implemented and called within the codebase. The internal_react_component method returns a hash with the keys :render_options, :tag, and :result, ensuring that the parameters passed to build_react_component_result_for_server_streamed_content are correctly defined.

  • stream_react_component method calls internal_react_component, which returns the necessary keys.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `build_react_component_result_for_server_streamed_content` are correctly implemented.

# Test: Search for the function usage. Expect: Correct implementation of the function calls.
rg --type ruby -A 5 $'build_react_component_result_for_server_streamed_content'

Length of output: 994


Script:

#!/bin/bash
# Description: Verify the context of the function call to `build_react_component_result_for_server_streamed_content` to ensure the parameters are correctly defined and passed.

# Search for the context around the function call to examine the definition of `result`.
rg --type ruby -A 10 -B 10 $'build_react_component_result_for_server_streamed_content('

Length of output: 253


Script:

#!/bin/bash
# Description: Verify the context of the function call to `build_react_component_result_for_server_streamed_content` to ensure the parameters are correctly defined and passed.

# Search for the context around the function call to examine the definition of `result`.
rg --type ruby -A 10 -B 10 $'build_react_component_result_for_server_streamed_content\('

Length of output: 3034


Script:

#!/bin/bash
# Description: Verify the return value of the `internal_react_component` method to ensure it returns a hash with the keys `:result`, `:tag`, and `:render_options`.

# Search for the definition of the `internal_react_component` method.
rg --type ruby -A 10 $'def internal_react_component'

Length of output: 989


Script:

#!/bin/bash
# Description: Retrieve the complete implementation of the `internal_react_component` method.

# Search for the complete implementation of the `internal_react_component` method.
rg --type ruby -A 50 -B 10 $'def internal_react_component'

Length of output: 4813

@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro362-add-support-for-RSC branch from 4e3ad5b to 440511d Compare July 30, 2024 07:47
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (2)
node_package/src/ReactOnRails.ts (1)

253-260: LGTM! Consider adding a more descriptive error message.

The implementation looks good. Consider providing more context in the error message to help developers understand why this method is not supported.

- throw new Error('serverRenderRSCReactComponent is supported in RSC bundle only.');
+ throw new Error('serverRenderRSCReactComponent is supported in RSC bundle only. Ensure you are using the correct bundle for React Server Components.');
CHANGELOG.md (1)

8-8: Format bare URL as a proper link.

Bare URLs should be formatted as proper links in markdown files.

- If you need help upgrading `react_on_rails`, `webpacker` to `shakapacker`, or JS packages, contact [email protected].
+ If you need help upgrading `react_on_rails`, `webpacker` to `shakapacker`, or JS packages, contact [[email protected]](mailto:[email protected]).
Tools
Markdownlint

8-8: null
Bare URL used

(MD034, no-bare-urls)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4e3ad5b and 440511d.

Files ignored due to path filters (2)
  • Gemfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (12)
  • CHANGELOG.md (2 hunks)
  • lib/react_on_rails/helper.rb (5 hunks)
  • lib/react_on_rails/react_component/render_options.rb (1 hunks)
  • lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb (1 hunks)
  • lib/react_on_rails/utils.rb (2 hunks)
  • node_package/src/ReactOnRails.ts (2 hunks)
  • node_package/src/ReactOnRailsRSC.ts (1 hunks)
  • node_package/src/serverRenderReactComponent.ts (4 hunks)
  • node_package/src/types/index.ts (2 hunks)
  • package.json (3 hunks)
  • spec/dummy/config/webpack/alias.js (1 hunks)
  • spec/dummy/config/webpack/webpackConfig.js (1 hunks)
Additional context used
Markdownlint
CHANGELOG.md

8-8: null
Bare URL used

(MD034, no-bare-urls)

Additional comments not posted (32)
spec/dummy/config/webpack/alias.js (1)

7-7: Alias addition for stream module looks good.

The alias for stream module mapping to stream-browserify enhances module resolution for browser environments.

spec/dummy/config/webpack/webpackConfig.js (1)

7-7: Fallback configuration for stream module looks good.

The fallback configuration for stream module using stream-browserify ensures compatibility for environments where the native stream module may not be available.

node_package/src/ReactOnRailsRSC.ts (5)

1-12: Import statements look good.

The import statements bring in necessary modules and types for the functionalities being introduced.


13-20: Async function for setting AsyncLocalStorage looks good.

The function attempts to set AsyncLocalStorage in the global scope and handles its absence gracefully.


22-27: stringToStream function looks good.

The function correctly converts a string to a stream using PassThrough.


29-37: getBundleConfig function looks good.

The function correctly reads the JSON file and processes its keys to remove the file:// prefix.


88-89: Export statements look good.

The export statements appropriately export types and the default ReactOnRails object.

package.json (2)

5-10: LGTM! The exports field enhances module compatibility.

The addition of the exports field provides more granular control over how the module is imported in different environments. Ensure that the paths to ReactOnRailsRSC.js and ReactOnRails.js are correct.


23-24: Approve dependency updates but verify compatibility.

The updates to @types/react, @types/react-dom, react, react-dom, and the addition of react-server-dom-webpack are approved. Ensure that these updates are compatible with the rest of the codebase and do not introduce breaking changes.

Also applies to: 47-49

lib/react_on_rails/react_component/render_options.rb (1)

106-113: LGTM! The new methods stream? and rsc? are well integrated.

The methods correctly retrieve the options from the options hash. Ensure that these options are set correctly in the codebase.

node_package/src/types/index.ts (1)

2-2: LGTM! The new methods streamServerRenderedReactComponent and serverRenderRSCReactComponent are well defined.

The methods are correctly integrated into the ReactOnRails interface. Ensure that these methods are implemented correctly in the codebase.

Also applies to: 141-142

node_package/src/serverRenderReactComponent.ts (4)

1-3: Imports look good.

The new imports ReactDOMServer and PassThrough are necessary for the new streaming rendering approach.


202-207: Function looks good.

The stringToStream function correctly converts a string to a stream.


209-248: Function looks good.

The streamServerRenderedReactComponent function correctly manages the rendering process and handles errors using the new streaming rendering approach.

However, ensure the new function is used correctly throughout the codebase.

Verification successful

Function looks good.

The streamServerRenderedReactComponent function correctly manages the rendering process and handles errors using the new streaming rendering approach.

However, ensure the new function is used correctly throughout the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new function.

# Test: Search for the function usage. Expect: Correct usage of `streamServerRenderedReactComponent`.
rg --type ts -A 5 $'streamServerRenderedReactComponent'

Length of output: 2064


74-101: New rendering approach looks good.

The use of renderToPipeableStream improves performance by streaming the rendered output. The function handles different rendering results and includes error handling.

However, ensure the new function is used correctly throughout the codebase.

lib/react_on_rails/utils.rb (3)

Line range hint 69-95:
Method looks good.

The bundle_js_file_path method has been renamed and modified to handle different bundle names dynamically. The error handling and default path construction are correct.


96-110: Method looks good.

The server_bundle_js_file_path method has been modified to use the new bundle_js_file_path method, improving maintainability.


112-117: Method looks good.

The new rsc_bundle_js_file_path method improves configurability by managing the retrieval of a resource bundle path.

lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb (1)

95-99: Method looks good.

The new exec_server_render_streaming_js method enhances functionality by providing an alternative for JavaScript execution with streaming capabilities.

node_package/src/ReactOnRails.ts (1)

245-251: LGTM! Verify the correct usage of RenderParams and streamServerRenderedReactComponent.

The implementation looks good. Ensure that RenderParams and streamServerRenderedReactComponent are correctly defined and imported.

Verification successful

Verified: The RenderParams and streamServerRenderedReactComponent are correctly defined and imported.

  • RenderParams is defined in node_package/src/types/index.ts.
  • streamServerRenderedReactComponent is defined in node_package/src/serverRenderReactComponent.ts and imported in node_package/src/ReactOnRails.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct usage of `RenderParams` and `streamServerRenderedReactComponent`.

# Test: Search for the definitions of `RenderParams` and `streamServerRenderedReactComponent`. Expect: Correct definitions and imports.
rg --type typescript -A 5 $'RenderParams'
rg --type typescript -A 5 $'streamServerRenderedReactComponent'

Length of output: 173


Script:

#!/bin/bash
# Description: Verify the correct usage of `RenderParams` and `streamServerRenderedReactComponent`.

# Test: Search for the definitions of `RenderParams` and `streamServerRenderedReactComponent`. Expect: Correct definitions and imports.
rg -A 5 'RenderParams'
rg -A 5 'streamServerRenderedReactComponent'

Length of output: 7052

lib/react_on_rails/helper.rb (5)

115-123: LGTM! Verify the correct usage of stream_react_component and Fiber.

The implementation looks good. Ensure that stream_react_component is correctly defined and that the Fiber usage is appropriate.

Verification successful

LGTM!

The implementation of stream_react_component_async and the usage of stream_react_component and Fiber are correct and consistent.

  • stream_react_component is correctly defined and used within stream_react_component_async.
  • The Fiber usage is appropriate for yielding chunks of data asynchronously.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct usage of `stream_react_component` and `Fiber`.

# Test: Search for the definition of `stream_react_component`. Expect: Correct definition and usage.
rg --type ruby -A 5 $'def stream_react_component'

# Test: Check for the usage of `Fiber`. Expect: Appropriate usage.
rg --type ruby -A 5 $'Fiber'

Length of output: 2275


94-103: LGTM! Verify the correct usage of internal_rsc_react_component and Fiber.

The implementation looks good. Ensure that internal_rsc_react_component is correctly defined and that the Fiber usage is appropriate.

Verification successful

LGTM! The implementation of rsc_react_component is correct.

  • The internal_rsc_react_component method is correctly defined and used.
  • The Fiber usage is appropriate and consistent.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct usage of `internal_rsc_react_component` and `Fiber`.

# Test: Search for the definition of `internal_rsc_react_component`. Expect: Correct definition and usage.
rg --type ruby -A 5 $'def internal_rsc_react_component'

# Test: Check for the usage of `Fiber`. Expect: Appropriate usage.
rg --type ruby -A 5 $'Fiber'

Length of output: 1924


105-113: LGTM! Verify the correct usage of internal_react_component and options modification.

The implementation looks good. Ensure that internal_react_component is correctly defined and that the options are appropriately modified for streaming.


396-420: LGTM! Verify the correct transformation logic.

The implementation looks good. Ensure that the transformation logic for the rendered HTML stream is correctly implemented.

Verification successful

Verified: The transformation logic for the rendered HTML stream in the method build_react_component_result_for_server_streamed_content is correctly implemented.

  • The first chunk includes the necessary hydration tags.
  • The subsequent chunks are correctly processed.
  • The final transformation ensures the HTML is marked as safe.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct transformation logic for the rendered HTML stream.

# Test: Search for the transformation logic in `build_react_component_result_for_server_streamed_content`. Expect: Correct implementation.
rg --type ruby -A 10 $'def build_react_component_result_for_server_streamed_content'

Length of output: 1107


Script:

#!/bin/bash
# Description: Retrieve the complete implementation of the method `build_react_component_result_for_server_streamed_content`.

# Search for the complete implementation of the method `build_react_component_result_for_server_streamed_content` in the Ruby file.
rg --type ruby -A 20 $'def build_react_component_result_for_server_streamed_content'

Length of output: 1744


Script:

#!/bin/bash
# Description: Retrieve the complete implementation of the method `build_react_component_result_for_server_streamed_content`.

# Search for the complete implementation of the method `build_react_component_result_for_server_streamed_content` in the Ruby file.
rg --type ruby -A 30 $'def build_react_component_result_for_server_streamed_content'

Length of output: 2428


483-487: LGTM! Verify the correct usage of server_rendered_react_component and the rsc option.

The implementation looks good. Ensure that server_rendered_react_component is correctly defined and that the rsc option is appropriately handled.

Verification successful

LGTM! The server_rendered_react_component method is correctly defined, and the rsc option is appropriately handled.

  • The server_rendered_react_component method includes logic for server-side rendering and error management.
  • The rsc option is set and checked within the rendering process, ensuring it is handled correctly.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct usage of `server_rendered_react_component` and the `rsc` option.

# Test: Search for the definition of `server_rendered_react_component`. Expect: Correct definition and usage.
rg --type ruby -A 5 $'def server_rendered_react_component'

# Test: Check for the handling of the `rsc` option. Expect: Appropriate handling.
rg --type ruby -A 5 $'options = options.merge(rsc?: true)'

Length of output: 542


Script:

#!/bin/bash
# Description: Gather full implementation of `server_rendered_react_component` and check for `rsc` option handling.

# Get the full implementation of `server_rendered_react_component`
rg --type ruby -A 20 $'def server_rendered_react_component' lib/react_on_rails/helper.rb

# Search for any usage of `rsc` option in the codebase
rg --type ruby 'rsc?: true'

Length of output: 1348


Script:

#!/bin/bash
# Description: Gather complete implementation of `server_rendered_react_component` and check for `rsc` option handling within `lib/react_on_rails/helper.rb`.

# Get the complete implementation of `server_rendered_react_component`
rg --type ruby -A 50 $'def server_rendered_react_component' lib/react_on_rails/helper.rb

# Search for any references to `rsc` within `lib/react_on_rails/helper.rb`
rg --type ruby 'rsc' lib/react_on_rails/helper.rb

Length of output: 3052

CHANGELOG.md (7)

9-9: LGTM!

The link is properly formatted.


10-10: LGTM!

The link is properly formatted.


20-20: LGTM!

The new version entry is properly formatted.


21-21: LGTM!

The new section header is properly formatted.


22-22: LGTM!

The new entry under the "Fixed" section is properly formatted.


1131-1131: LGTM!

The link to the "Unreleased" comparison is properly formatted.


1132-1132: LGTM!

The link to the [14.0.1] comparison is properly formatted.

Comment on lines +39 to +86
ReactOnRails.serverRenderRSCReactComponent = (options: RenderParams) => {
const { name, domNodeId, trace, props, railsContext, throwJsErrors } = options;

let renderResult: null | PassThrough = null;

try {
const componentObj = ComponentRegistry.get(name);
if (componentObj.isRenderer) {
throw new Error(`\
Detected a renderer while server rendering component '${name}'. \
See https://github.com/shakacode/react_on_rails#renderer-functions`);
}

const reactRenderingResult = createReactOutput({
componentObj,
domNodeId,
trace,
props,
railsContext,
});

if (isServerRenderHash(reactRenderingResult) || isPromise(reactRenderingResult)) {
throw new Error('Server rendering of streams is not supported for server render hashes or promises.');
}

renderResult = new PassThrough();
const streamReader = renderToReadableStream(reactRenderingResult, getBundleConfig()).getReader();
const processStream = async () => {
const { done, value } = await streamReader.read();
if (done) {
renderResult?.push(null);
return;
}

renderResult?.push(value);
processStream();
}
processStream();
} catch (e: unknown) {
if (throwJsErrors) {
throw e;
}

renderResult = stringToStream(`Error: ${e}`);
}

return renderResult;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serverRenderRSCReactComponent function looks good.

The function performs server-side rendering for React components and includes error handling and stream processing.

Reminder: Add unit tests for serverRenderRSCReactComponent.

Ensure that unit tests are added to cover the new server-side rendering functionality.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro362-add-support-for-RSC branch from 440511d to 1c026a7 Compare July 30, 2024 12:43
@AbanoubGhadban AbanoubGhadban changed the base branch from master to abanoubghadban/pro403-use-render-to-readable-stream-to-render-async July 30, 2024 12:43
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 440511d and 1c026a7.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (16)
  • .gitignore (1 hunks)
  • jest.config.js (1 hunks)
  • lib/react_on_rails/helper.rb (5 hunks)
  • lib/react_on_rails/react_component/render_options.rb (1 hunks)
  • lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb (1 hunks)
  • lib/react_on_rails/utils.rb (3 hunks)
  • node_package/src/ReactOnRails.ts (2 hunks)
  • node_package/src/ReactOnRailsRSC.ts (1 hunks)
  • node_package/src/serverRenderReactComponent.ts (2 hunks)
  • node_package/src/types/index.ts (2 hunks)
  • node_package/tests/ReactOnRails.test.js (1 hunks)
  • node_package/tests/jest.setup.js (1 hunks)
  • package.json (3 hunks)
  • spec/dummy/config/webpack/alias.js (1 hunks)
  • spec/dummy/config/webpack/commonWebpackConfig.js (1 hunks)
  • spec/dummy/config/webpack/webpackConfig.js (1 hunks)
Files skipped from review due to trivial changes (2)
  • .gitignore
  • spec/dummy/config/webpack/alias.js
Files skipped from review as they are similar to previous changes (7)
  • lib/react_on_rails/helper.rb
  • lib/react_on_rails/react_component/render_options.rb
  • lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb
  • node_package/src/ReactOnRailsRSC.ts
  • node_package/src/types/index.ts
  • package.json
  • spec/dummy/config/webpack/webpackConfig.js
Additional comments not posted (14)
jest.config.js (1)

4-4: Ensure the setup script exists and is correctly placed.

The setupFiles option specifies a setup script located at <rootDir>/node_package/tests/jest.setup.js. Verify that this file exists and is correctly configured.

Verification successful

The setup script node_package/tests/jest.setup.js exists and is correctly configured.

  • The script contains necessary polyfills for TextEncoder and TextDecoder in the jsdom environment, ensuring Jest tests run smoothly.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the setup script exists at the specified location.

# Test: Check if the file exists. Expect: The file should exist.
if [ ! -f "node_package/tests/jest.setup.js" ]; then
  echo "Error: The setup script node_package/tests/jest.setup.js does not exist."
  exit 1
fi
echo "The setup script node_package/tests/jest.setup.js exists."

Length of output: 174


Script:

#!/bin/bash
# Description: Output the contents of the jest.setup.js file to verify its configuration.

# Display the contents of the setup script
cat node_package/tests/jest.setup.js

Length of output: 672

node_package/tests/jest.setup.js (1)

1-13: Ensure polyfills do not conflict with existing definitions.

The polyfills for TextEncoder and TextDecoder are necessary for environments where they are not defined. Ensure that these polyfills do not conflict with any existing definitions.

Verification successful

No conflicting definitions of TextEncoder and TextDecoder found.

The verification process confirms that there are no existing definitions or imports of TextEncoder and TextDecoder in the codebase. The polyfills in node_package/tests/jest.setup.js do not conflict with any existing definitions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the polyfills for TextEncoder and TextDecoder do not conflict with existing definitions.

# Test: Check if TextEncoder and TextDecoder are already defined in the global scope. Expect: They should not be defined.
node -e "if (typeof global.TextEncoder !== 'undefined' || typeof global.TextDecoder !== 'undefined') { console.error('Error: TextEncoder or TextDecoder is already defined.'); process.exit(1); } else { console.log('TextEncoder and TextDecoder are not defined.'); }"

Length of output: 362


Script:

#!/bin/bash
# Search for any definitions or imports of TextEncoder and TextDecoder in the codebase
ast-grep --lang javascript --pattern 'const TextEncoder = $_;' 
ast-grep --lang javascript --pattern 'const TextDecoder = $_;' 
ast-grep --lang javascript --pattern 'import { TextEncoder } from $_;' 
ast-grep --lang javascript --pattern 'import { TextDecoder } from $_;' 

Length of output: 1183


Script:

#!/bin/bash
# Corrected ast-grep patterns for searching definitions or imports of TextEncoder and TextDecoder in the codebase
ast-grep --lang javascript --pattern 'const TextEncoder = $_;'
ast-grep --lang javascript --pattern 'const TextDecoder = $_;'
ast-grep --lang javascript --pattern 'import { TextEncoder } from "$_";'
ast-grep --lang javascript --pattern 'import { TextDecoder } from "$_";'

# Fallback to rg for searching definitions or imports of TextEncoder and TextDecoder in the codebase
rg 'const TextEncoder' --context 5
rg 'const TextDecoder' --context 5
rg 'import { TextEncoder' --context 5
rg 'import { TextDecoder' --context 5

Length of output: 657


Script:

#!/bin/bash
# Corrected rg patterns for searching definitions or imports of TextEncoder and TextDecoder in the codebase
rg 'const TextEncoder' --context 5
rg 'const TextDecoder' --context 5
rg 'import \{ TextEncoder' --context 5
rg 'import \{ TextDecoder' --context 5

Length of output: 155

spec/dummy/config/webpack/commonWebpackConfig.js (1)

44-44: Ensure compatibility with the new process configuration.

The addition of process: 'process/browser' in the ProvidePlugin configuration is intended to improve compatibility with certain libraries. Verify that this change does not introduce any conflicts or issues.

Verification successful

Verification successful: The new process configuration does not introduce any conflicts or issues.

The addition of process: 'process/browser' in the ProvidePlugin configuration is intended to provide a polyfill for the process object in the browser environment. The search results indicate that the process object is used primarily for setting and checking environment variables, which should not be affected by this change.

  • spec/dummy/babel.config.js
  • spec/dummy/config/webpack/webpackConfig.js
  • spec/dummy/config/webpack/test.js
  • spec/dummy/config/webpack/production.js
  • spec/dummy/config/webpack/development.js
  • spec/dummy/config/webpack/commonWebpackConfig.js
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new process configuration does not introduce any conflicts or issues.

# Test: Check if the process object is available globally in the browser environment. Expect: The process object should be defined.
node -e "const webpack = require('webpack'); const config = require('./spec/dummy/config/webpack/commonWebpackConfig.js')(); webpack(config, (err, stats) => { if (err || stats.hasErrors()) { console.error('Error: Webpack compilation failed.'); process.exit(1); } else { console.log('Webpack compilation succeeded.'); } });"

Length of output: 421


Script:

#!/bin/bash
# Description: Search for the usage of the `process` object in the codebase to identify potential issues or conflicts.

# Search for the usage of `process` in JavaScript files
rg 'process' --glob '*.js' -A 3

Length of output: 2474

node_package/tests/ReactOnRails.test.js (1)

22-30: LGTM! Improved test clarity by directly manipulating the DOM.

The changes enhance the clarity of the test by directly manipulating the DOM and checking the visible output rather than relying on internal component details.

node_package/src/serverRenderReactComponent.ts (4)

2-2: LGTM! New import for PassThrough stream.

The PassThrough stream from the stream module is correctly imported for use in the new rendering approach.


170-175: LGTM! New function stringToStream correctly implemented.

The function converts a string to a stream using PassThrough, which is useful for converting error messages to streams.


177-219: LGTM! Enhanced server-side rendering with renderToPipeableStream.

The new function streamServerRenderedReactComponent enhances server-side rendering by allowing for more efficient streaming of rendered output. Error handling and logging are appropriately implemented.


219-220: LGTM! Correct return statement for renderResult.

The return statement correctly returns the renderResult stream.

lib/react_on_rails/utils.rb (3)

Line range hint 69-97:
LGTM! Enhanced flexibility with bundle_js_file_path.

The new method bundle_js_file_path enhances the flexibility of the bundle path retrieval process by allowing it to handle different bundle names dynamically.


98-112: LGTM! Streamlined logic with bundle_js_file_path.

The method server_bundle_js_file_path has been updated to use the new bundle_js_file_path method, streamlining the logic for retrieving the server bundle path.


114-119: LGTM! New method rsc_bundle_js_file_path enhances configurability.

The new method rsc_bundle_js_file_path enhances configurability by allowing the retrieval of a resource bundle path, with a default bundle name for the development environment.

node_package/src/ReactOnRails.ts (3)

262-264: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to handleError are correctly implemented.

Verification successful

All usages of handleError are correctly implemented.

The function handleError is consistently used across the codebase, and no issues were found.

  • serverRenderReactComponent.ts: Multiple valid usages.
  • ReactOnRails.ts: Valid usage.
  • handleError.ts: Proper definition and export.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `handleError` are correctly implemented.

# Test: Search for the function usage. Expect: Only valid occurrences.
rg --type python -A 5 $'handleError'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify all function calls to `handleError` are correctly implemented.

# Test: Search for the function usage. Expect: Only valid occurrences.
rg --type ts -A 5 $'handleError'

Length of output: 3682


258-260: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to serverRenderRSCReactComponent are correctly implemented.

Verification successful

Function usage verified.

The function serverRenderRSCReactComponent is correctly implemented and used only in the appropriate context.

  • Definition and error throwing: node_package/src/ReactOnRails.ts
  • Implementation for RSC bundle: node_package/src/ReactOnRailsRSC.ts
  • Type declaration: node_package/src/types/index.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `serverRenderRSCReactComponent` are correctly implemented.

# Test: Search for the function usage. Expect: Only valid occurrences.
rg --type python -A 5 $'serverRenderRSCReactComponent'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify all function calls to `serverRenderRSCReactComponent` are correctly implemented.

# Test: Search for the function usage. Expect: Only valid occurrences.
rg --type ts -A 5 $'serverRenderRSCReactComponent'

Length of output: 1445


249-251: LGTM! Verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to streamServerRenderedReactComponent are correctly implemented.

Verification successful

Verification Successful: Function usage is correct.

The streamServerRenderedReactComponent function is correctly implemented and used within the codebase.

  • Definition: node_package/src/serverRenderReactComponent.ts
  • Usage: node_package/src/ReactOnRails.ts
  • Type Declaration: node_package/src/types/index.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `streamServerRenderedReactComponent` are correctly implemented.

# Test: Search for the function usage. Expect: Only valid occurrences.
rg --type python -A 5 $'streamServerRenderedReactComponent'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify all function calls to `streamServerRenderedReactComponent` are correctly implemented.

# Test: Search for the function usage. Expect: Only valid occurrences.
rg --type ts -A 5 $'streamServerRenderedReactComponent'

Length of output: 2038

Comments failed to post (1)
node_package/src/serverRenderReactComponent.ts

205-207: Reminder: Add console replay script to the stream.

The TODO comment indicates that the console replay script needs to be added to the stream to avoid console messages leaking between different components rendering.

Do you want me to generate the code for adding the console replay script to the stream or open a GitHub issue to track this task?

@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro362-add-support-for-RSC branch from 1c026a7 to 40c89e4 Compare July 30, 2024 13:54
Comment on lines +354 to +360
# 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}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed or is the plan to revert (if so, better to add a comment)?

@@ -574,7 +593,7 @@ def server_rendered_react_component(render_options)
end

# TODO: handle errors for streams
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still left as TODO?

Comment on lines +82 to +84
rescue Object.const_get(
ReactOnRails::PackerUtils.packer_type.capitalize
)::Manifest::MissingEntryError
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it could easily raise an error itself. Any way around it?

Comment on lines -104 to +93
# For Shakapacker, this is the public output path defined in the (shaka/web)packer.yml file.
# For Webpacker, this is the public output path defined in the webpacker.yml file.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be reverted.

File.join(generated_assets_full_path, bundle_name)
end
end

def self.server_bundle_js_file_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit from moving it here? The drawback is less clear diff.

@@ -250,6 +250,15 @@ ctx.ReactOnRails = {
return streamServerRenderedReactComponent(options);
},

/**
* Used by server rendering by Rails
* @param options
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No use including this line without a description.

Comment on lines +47 to +49
"react": "18.3.0-canary-670811593-20240322",
"react-dom": "18.3.0-canary-670811593-20240322",
"react-server-dom-webpack": "18.3.0-canary-670811593-20240322",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,89 @@
import type { ReactElement } from 'react';
// @ts-expect-error will define this module types later
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't forget to.

@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch from f38ed50 to 0c2313e Compare September 30, 2024 13:44
@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch 2 times, most recently from 24e30fa to 64ce293 Compare October 15, 2024 08:46
@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch 2 times, most recently from d5d5d68 to 8937c5f Compare October 20, 2024 11:45
Base automatically changed from abanoubghadban/pro403-use-render-to-readable-stream-to-render-async to master October 29, 2024 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants