Closed AbanoubGhadban closed 4 weeks ago
This update enhances the react_on_rails
library by introducing robust server-side streaming capabilities for React components. Significant new methods have been added in both Ruby and JavaScript to facilitate asynchronous rendering, improve error handling, and ensure compatibility with the latest package versions. Additionally, the Webpack configuration has been adjusted to support these features, and various test setups have been refined.
Files/Paths | Change Summary |
---|---|
jest.config.js |
Added setupFiles property for test suite configuration. |
lib/react_on_rails/helper.rb |
Added streaming methods for React components and refactored existing methods for clarity and functionality. |
lib/react_on_rails/react_component/render_options.rb , lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb |
Added new methods for streaming options and JavaScript rendering capabilities. |
node_package/src/ReactOnRails.ts , node_package/src/types/index.ts , node_package/src/serverRenderReactComponent.ts |
Introduced streamServerRenderedReactComponent for server-side React streaming; updated interface for new functionality. |
node_package/tests/ReactOnRails.test.js |
Improved test setup for rendering checks. |
node_package/tests/jest.setup.js |
Introduced a polyfill for TextEncoder and TextDecoder . |
package.json |
Upgraded react and react-dom versions to 18.2.0 . |
spec/dummy/config/webpack/alias.js , spec/dummy/config/webpack/commonWebpackConfig.js , spec/dummy/config/webpack/webpackConfig.js |
Configured webpack to support streaming with stream-browserify and added Node.js globals compatibility. |
spec/dummy/spec/helpers/react_on_rails_helper_spec.rb |
Added tests for rails_context_if_not_already_rendered method to ensure correct behavior and output. |
setupFiles
in jest.config.js
, which is related to the configuration of test setups. This is relevant to the changes in the lib/react_on_rails/helper.rb
file, where the loading behavior of React components is enhanced, potentially impacting how tests are set up and executed.serverRenderReactComponent
function in this PR may relate to the changes in the main PR as both involve modifications to the server rendering logic, which could affect how tests are structured and executed in relation to server-rendered components.react_on_rails
library.react_on_rails
library.In the garden where bytes flow,
A new feature begins to grow.
Streaming React with seamless grace,
Swiftly dancing in data's embrace.
Rails and JavaScript, hand in hand,
Server to client, perfectly planned.
🌱🚀🎉
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?
Would it make sense to add async: false parameter to def stream_react_component instead of a separate function (probably not, but asking just in case)?
The stream_react_component_async
is renamed now to stream_react_component
. It's async by default. The other function is removed
@AbanoubGhadban let's see if this is ready for merge and pre-release.
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_components
in the dummy app.More resources
https://react.dev/reference/react-dom/server/renderToPipeableStream https://github.com/reactwg/react-18/discussions/37
Sequence Diagrams
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Updates
This change is