Skip to content

Conversation

@AbanoubGhadban
Copy link
Contributor

@AbanoubGhadban AbanoubGhadban commented Jun 17, 2024

Summary

This PR introduces the new features introduced in React 18 which is supporting Async Components and streaming components. It's done by replacing renderToString function with renderToPipeableStream.
https://www.loom.com/share/db55036514b746a7b283e6f296134168?sid=2ce8205d-6956-4e9a-97bc-ee55004f3216

The Dummy App

To open the newly introduced page in the dummy app, you need to clone both React on Rails and React on Rails Pro on your local machine and put them in the same directory

  • <parent_directory>
    • react_on_rails
    • react_on_rails_pro

execute the following commands

cd <parent_directory>
cd react_on_rails
bundle && yarn
cd ../react_on_rails_pro
bundle && yarn
cd spec/dummy
bundle && yarn

bin/dev

Then, open the newly introduced stream_async_components in the dummy app.

More resources

https://react.dev/reference/react-dom/server/renderToPipeableStream
reactwg/react-18#37

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced CI pipeline with new steps to ensure the Rails server is operational before executing tests.
    • Updated dependency management with new versions of React and React DOM, including local linking for react-on-rails.
    • Introduced streaming capabilities for efficient rendering of React components, including methods for handling streaming requests and console output.
    • Added new endpoints for streaming asynchronous components and console logging in an asynchronous server context.
    • Implemented a new React component for fetching and displaying posts and comments asynchronously.
    • Comprehensive documentation updates on streaming server rendering and caching mechanisms.
    • Added a new helper method for streaming server rendering support.
    • Introduced a new module for handling streaming and transformations of data chunks.
  • Bug Fixes

    • Improved caching mechanisms to reduce conflicts and streamline the build process.
  • Chores

    • Updated scripts for local development to enhance pre-installation processes and build workflows.
    • Enhanced the ResponseResult interface to support streaming data and introduced utility functions for better stream handling.

@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

The recent updates enhance the CI/CD pipeline for a Ruby on Rails application with a Node.js frontend, particularly focusing on streaming capabilities and improved documentation. Modifications include the addition of new commands in the CircleCI configuration to ensure the Rails server is operational before running tests. The documentation has been expanded to cover new features in React 18, including server-side rendering enhancements and caching strategies. New classes and methods have been introduced to facilitate streaming, improving the overall rendering process and testing capabilities.

Changes

File Summary
.circleci/config.yml - Added commands to run the Rails server in the background and wait for its availability before executing RSpec tests.
docs/home-pro.md - Updated documentation to include new features in React 18, including "Next-Gen Server Rendering" and caching mechanisms.
docs/streaming-server-rendering.md - Introduced a guide for implementing streaming server rendering using React 18's APIs.
lib/react_on_rails_pro.rb - Added require "react_on_rails_pro/stream" to include streaming functionality.
lib/react_on_rails_pro/request.rb - Introduced render_code_as_stream method for handling streaming responses.
lib/react_on_rails_pro/server_rendering_js_code.rb - Updated render method to select rendering function based on streaming options.
lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb - Added methods for executing JavaScript in streaming scenarios.
lib/react_on_rails_pro/stream.rb - Introduced ReactOnRailsPro::Stream module for streaming React components.
lib/react_on_rails_pro/stream_request.rb - Added StreamDecorator and StreamRequest classes for managing streaming data transformations and requests.
packages/node-renderer/src/shared/sharedConsoleHistory.ts - Updated console message handling to improve type safety and support readable streams.
packages/node-renderer/src/worker.ts - Enhanced asynchronous handling of responses and checks within the Fastify application.
packages/node-renderer/src/worker/handleRenderRequest.ts - Improved response handling logic to support streaming results.
packages/node-renderer/src/worker/vm.ts - Updated type definitions and handling of rendering results in the virtual machine context.
spec/dummy/app/controllers/pages_controller.rb - Added methods for streaming React components and testing functionalities.
spec/dummy/config/routes.rb - Introduced new routes for streaming actions.
spec/dummy/package.json - Updated react and react-dom to canary releases.
spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb - Added StreamingTestHelpers module to enhance testing for streaming components.
spec/dummy/spec/system/integration_spec.rb - Introduced tests for the new streaming functionality and updated existing methods for flexibility.

Poem

🐇 In CircleCI's embrace, we clone and cache,
React-on-Rails, a speedy dash!
Dependencies dance, versions align,
With each new change, our code will shine.
Hops of efficiency, through scripts we play,
A smoother path for devs today! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c03e1d2 and 099e87f.

📒 Files selected for processing (1)
  • spec/dummy/spec/helpers/react_on_rails_pro_helper_spec.rb (2 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.


# For local development
# gem "react_on_rails", path: "../react_on_rails"
gem "react_on_rails", path: "../react_on_rails"
Copy link
Member

Choose a reason for hiding this comment

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

try not to push this file

you can locally ignore during dev if you want to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will merge the React on Rails PR first. Then, we can revert this change.

@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch 2 times, most recently from 1eb85db to 130bcb7 Compare July 24, 2024 14:09
if ReactOnRailsPro.configuration.prerender_caching &&
render_options.internal_option(:skip_prerender_cache).nil?
render_options.internal_option(:skip_prerender_cache).nil? &&
!render_options.stream?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ability to cache streams will be added in a follow up PR

@@ -0,0 +1,16 @@
module ReactOnRailsPro
module Stream
def stream_view_containing_react_components(template:, close_stream_at_end: true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The primary helper function is used in the controller to render any view containing streamable react components. See PagesController to see how this function is used.

@@ -0,0 +1,4 @@
<%= stream_react_component_async("StreamAsyncComponents", props: @app_props_server_render, prerender: true, trace: true, id: "StreamAsyncComponents-react-component-0") %>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function can only be called inside views rendered using stream_view_containing_react_components function

Copy link
Contributor Author

@AbanoubGhadban AbanoubGhadban left a comment

Choose a reason for hiding this comment

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

Self-reviewed

@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch from da6f905 to fb2a5ab Compare July 30, 2024 08:47
- v4-package-app-gem-cache-{{ checksum "react_on_rails_pro.gemspec" }}

# Restore react-on-rails from cache
- &restore-react-on-rails-cache
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change will be reverted after merging the react on rails PR.

@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch from 1913c16 to 81d31f6 Compare September 30, 2024 14:30
@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch 3 times, most recently from e8858b9 to c8b5c5b Compare October 15, 2024 14:09
@AbanoubGhadban AbanoubGhadban changed the base branch from master to abanoubghadban/pro362-add-support-for-RSC October 15, 2024 15:12
@AbanoubGhadban AbanoubGhadban changed the base branch from abanoubghadban/pro362-add-support-for-RSC to abanoubghadban/pro439-add-support-for-replaying-logs-happen-on-async-server-operations October 15, 2024 15:12
@AbanoubGhadban AbanoubGhadban changed the title [WIP] Add support for streaming rendered components using renderToPipeableStream Add support for streaming rendered components using renderToPipeableStream Oct 15, 2024
AbanoubGhadban and others added 22 commits November 1, 2024 17:11
Co-authored-by: Alexey Romanov <104450112+alexeyr-ci@users.noreply.github.com>
Co-authored-by: Alexey Romanov <104450112+alexeyr-ci@users.noreply.github.com>
Co-authored-by: Alexey Romanov <104450112+alexeyr-ci@users.noreply.github.com>
Co-authored-by: Alexey Romanov <104450112+alexeyr-ci@users.noreply.github.com>
Co-authored-by: Alexey Romanov <104450112+alexeyr-ci@users.noreply.github.com>
Co-authored-by: Alexey Romanov <104450112+alexeyr-ci@users.noreply.github.com>
Co-authored-by: Alexey Romanov <104450112+alexeyr-ci@users.noreply.github.com>
update docs

update docs

update streaming docs
@AbanoubGhadban AbanoubGhadban force-pushed the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch from 4b0614e to 6cc2b0c Compare November 1, 2024 15:17
@AbanoubGhadban AbanoubGhadban merged commit 4b7c863 into master Nov 1, 2024
4 of 8 checks passed
@AbanoubGhadban AbanoubGhadban deleted the abanoubghadban/pro403-use-render-to-readable-stream-to-render-async branch November 1, 2024 15:44
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.

4 participants