-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for streaming rendered components using renderToPipeableStream
#407
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
Add support for streaming rendered components using renderToPipeableStream
#407
Conversation
WalkthroughThe 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
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
Note 🎁 Summarized by CodeRabbit FreeYour 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Gemfile.development_dependencies
Outdated
|
|
||
| # For local development | ||
| # gem "react_on_rails", path: "../react_on_rails" | ||
| gem "react_on_rails", path: "../react_on_rails" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb
Outdated
Show resolved
Hide resolved
1eb85db to
130bcb7
Compare
| if ReactOnRailsPro.configuration.prerender_caching && | ||
| render_options.internal_option(:skip_prerender_cache).nil? | ||
| render_options.internal_option(:skip_prerender_cache).nil? && | ||
| !render_options.stream? |
There was a problem hiding this comment.
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) | |||
There was a problem hiding this comment.
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") %> | |||
There was a problem hiding this comment.
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
AbanoubGhadban
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-reviewed
lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb
Outdated
Show resolved
Hide resolved
da6f905 to
fb2a5ab
Compare
.circleci/config.yml
Outdated
| - v4-package-app-gem-cache-{{ checksum "react_on_rails_pro.gemspec" }} | ||
|
|
||
| # Restore react-on-rails from cache | ||
| - &restore-react-on-rails-cache |
There was a problem hiding this comment.
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.
spec/dummy/client/app/ror-auto-load-components/StreamAsyncComponents.jsx
Outdated
Show resolved
Hide resolved
spec/dummy/client/app/ror-auto-load-components/StreamAsyncComponents.jsx
Outdated
Show resolved
Hide resolved
spec/dummy/client/app/ror-auto-load-components/StreamAsyncComponents.jsx
Show resolved
Hide resolved
1913c16 to
81d31f6
Compare
e8858b9 to
c8b5c5b
Compare
renderToPipeableStreamrenderToPipeableStream
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
4b0614e to
6cc2b0c
Compare
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
execute the following commands
Then, open the newly introduced
stream_async_componentsin 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
react-on-rails.Bug Fixes
Chores