react_on_rails
react_on_rails copied to clipboard
should force load react-components which send over turbo-stream
Summary
Support React On Rails w/Hotwire and Turbo Streams https://github.com/shakacode/react_on_rails/issues/1493, https://github.com/shakacode/react_on_rails/issues/1508
All turbo events (turbo:before-render, turbo:render,.. ) will not dispatch with TurboStream, except turbo:before-stream-render. And it looks like turbo-rails did not support a after-stream-render event, i don't know why yet.
But hotwired send html, react_on_rails send script, right ? So my solution: send a script that will trigger load react component along with it.
Pull Request checklist
-
i add a new render option: force_load which if true then the trigger load script will be concat with the component itself.
-
i not use reactOnRailsPageLoaded which will query and reload all current react-components (not effective), i introduce new method reactOnRailsComponentLoaded(react-component-dom-id) to load directly the react-component that the script be sent along with.
Other Information
Summary by CodeRabbit
-
New Features
- Introduced a new
force_loadconfiguration option for React components, allowing immediate loading. - Added Turbo Frame and Turbo Stream support, enabling dynamic updates and interactions.
- Created a new React component
HelloTurboStreamfor enhanced user interaction.
- Introduced a new
-
Bug Fixes
- Ensured proper rendering and unmounting of React components based on
domId.
- Ensured proper rendering and unmounting of React components based on
-
Documentation
- Updated examples and documentation to reflect new
force_loadand Turbo functionality.
- Updated examples and documentation to reflect new
-
Tests
- Added tests for new Turbo Stream functionality and
force_loadconfiguration.
- Added tests for new Turbo Stream functionality and
Walkthrough
This update enhances the react_on_rails library by integrating Turbo Streams, improving the responsiveness and dynamic loading of components. Key features include the introduction of a force_load configuration option, optimizations in helper methods, and the implementation of Turbo Stream templates, all aimed at enabling smoother and more interactive React component rendering in Rails applications.
Changes
| Files/Paths | Change Summary |
|---|---|
Gemfile.development_dependencies |
Added gem "turbo-rails" to development dependencies. |
lib/react_on_rails/configuration.rb |
Introduced force_load configuration option with default false. Updated Configuration class. |
lib/react_on_rails/helper.rb |
Enhanced internal_react_component to check for force_load. |
lib/react_on_rails/react_component/render_options.rb, node_package/src/types/index.ts |
Added force_load method to retrieve configuration value. |
node_package/src/ReactOnRails.ts, node_package/src/clientStartup.ts |
Added reactOnRailsComponentLoaded method for component loading integration. |
spec/dummy/app/controllers/pages_controller.rb |
Introduced @app_props_hello_from_turbo_stream for Turbo Stream data. |
spec/dummy/app/views/pages/turbo_frame_tag_hello_world.html.erb, spec/dummy/app/views/pages/turbo_stream_send_hello_world.turbo_stream.erb |
Added Turbo Frame and Turbo Stream template for component updates. |
spec/dummy/client/app/packs/client-bundle.js |
Updated ReactOnRails options to include Turbo integration. |
spec/dummy/client/app/startup/HelloTurboStream.jsx |
Introduced HelloTurboStream React component with prop types. |
spec/dummy/config/routes.rb |
Added routes for Turbo integration. |
spec/dummy/package.json |
Added @hotwired/turbo-rails dependency. |
spec/dummy/spec/helpers/react_on_rails_helper_spec.rb |
Expanded tests for force_load option in react_component method. |
spec/dummy/spec/system/integration_spec.rb |
Added test for immediate loading of TurboStream component. |
spec/react_on_rails/react_component/render_options_spec.rb |
Included force_load option in testing configurations. |
π
In the world of code, a stream does flow,
React and Rails, together they grow.
With Turbo's speed and forceful load,
Components dance, in real-time mode.πβ¨
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?
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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto 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.yamlfile 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.
@theforestvn88 Please
- Check the
coderabitaisuggestions - fix the CI failure on liniting
- Rebase on master, and check CI failures.
@Judahmeek did you see anything requiring changes?
@theforestvn88 can you check if your PR solves the problem in https://github.com/shakacode/react_on_rails/issues/1508#issuecomment-1499730248?
Looks good.
@G-Rath any opinions on this PR?
@theforestvn88 can you fix the lint errors?
@theforestvn88 can you fix the lint errors?
i don't know what/where the lint errors are, the command nps format.listDifferent just return exit code 1.
Please help me !
Need new task to update https://github.com/shakacode/react_on_rails/blob/master/docs/rails/turbolinks.md#using-turbo
Merging...