react_on_rails icon indicating copy to clipboard operation
react_on_rails copied to clipboard

should force load react-components which send over turbo-stream

Open theforestvn88 opened this issue 1 year ago β€’ 5 comments

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


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Introduced a new force_load configuration option for React components, allowing immediate loading.
    • Added Turbo Frame and Turbo Stream support, enabling dynamic updates and interactions.
    • Created a new React component HelloTurboStream for enhanced user interaction.
  • Bug Fixes

    • Ensured proper rendering and unmounting of React components based on domId.
  • Documentation

    • Updated examples and documentation to reflect new force_load and Turbo functionality.
  • Tests

    • Added tests for new Turbo Stream functionality and force_load configuration.

theforestvn88 avatar May 16 '24 08:05 theforestvn88

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?

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.

coderabbitai[bot] avatar May 16 '24 08:05 coderabbitai[bot]

@theforestvn88 Please

  1. Check the coderabitai suggestions
  2. fix the CI failure on liniting
  3. Rebase on master, and check CI failures.

@Judahmeek did you see anything requiring changes?

justin808 avatar May 21 '24 04:05 justin808

@theforestvn88 can you check if your PR solves the problem in https://github.com/shakacode/react_on_rails/issues/1508#issuecomment-1499730248?

justin808 avatar May 21 '24 04:05 justin808

Looks good.

justin808 avatar Jun 12 '24 03:06 justin808

@G-Rath any opinions on this PR?

justin808 avatar Jun 14 '24 05:06 justin808

@theforestvn88 can you fix the lint errors?

justin808 avatar Jul 26 '24 05:07 justin808

@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 !

theforestvn88 avatar Jul 26 '24 11:07 theforestvn88

Need new task to update https://github.com/shakacode/react_on_rails/blob/master/docs/rails/turbolinks.md#using-turbo

Merging...

justin808 avatar Aug 20 '24 23:08 justin808