You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for streaming server side rendering (#1633)
* tmp
* add support for streaming rendered component using renderToPipeableStream
* put ROR scripts after the first rendered chunk
* remove log statements
* add stream_react_component_async helper function
* add helper function to render a whole view
* fix failing jest tests
* linting
* linting
* remove redundant new line when context is not prepended
* rename stream_react_component_async to stream_react_component
* fix error caused by process on browser
* remove new line appended to the page when has no rails context
* fix the problem of not updating the first streaming chunk
* rename stream_react_component_internal to internal_stream_react_component
* add unit tests for rails_context_if_not_already_rendered
* remove :focus tag from rails_context_if_not_already_rendered spec
* make render function returns Readable stream instead of PassThrough
* use validateComponent function instead of manually validating it
* linting
* add some comments
* don't return extra null at he end of the stream
* update CHANGELOG.md
* update docs
* update docs
Copy file name to clipboardExpand all lines: CHANGELOG.md
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,13 @@ Please follow the recommendations outlined at [keepachangelog.com](http://keepac
18
18
### [Unreleased]
19
19
Changes since the last non-beta release.
20
20
21
+
### Added
22
+
- Added streaming server rendering support:
23
+
- New `stream_react_component` helper for adding streamed components to views
24
+
- New `streamServerRenderedReactComponent` function in the react-on-rails package that uses React 18's `renderToPipeableStream` API
25
+
- Enables progressive page loading and improved performance for server-rendered React components
26
+
[PR #1633](https://github.com/shakacode/react_on_rails/pull/1633) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
27
+
21
28
#### Changed
22
29
- Console replay script generation now awaits the render request promise before generating, allowing it to capture console logs from asynchronous operations. This requires using a version of the Node renderer that supports replaying async console logs. [PR #1649](https://github.com/shakacode/react_on_rails/pull/1649) by [AbanoubGhadban](https://github.com/AbanoubGhadban).
React on Rails Pro supports streaming server rendering using React 18's latest APIs, including `renderToPipeableStream` and Suspense. This guide explains how to implement and optimize streaming server rendering in your React on Rails application.
4
+
5
+
## Prerequisites
6
+
7
+
- React on Rails Pro subscription
8
+
- React 18 or higher (experimental version)
9
+
- React on Rails v15.0.0-alpha.0 or higher
10
+
- React on Rails Pro v4.0.0.rc.5 or higher
11
+
12
+
## Benefits of Streaming Server Rendering
13
+
14
+
- Faster Time to First Byte (TTFB)
15
+
- Progressive page loading
16
+
- Improved user experience
17
+
- Better SEO performance
18
+
- Optimal handling of data fetching
19
+
20
+
## Implementation Steps
21
+
22
+
1.**Use Experimental React 18 Version**
23
+
24
+
First, ensure you're using React 18's experimental version in your package.json:
25
+
26
+
```json
27
+
"dependencies": {
28
+
"react": "18.3.0-canary-670811593-20240322",
29
+
"react-dom": "18.3.0-canary-670811593-20240322"
30
+
}
31
+
```
32
+
33
+
> Note: Check the React documentation for the latest release that supports streaming.
34
+
35
+
2.**Prepare Your React Components**
36
+
37
+
You can create async React components that return a promise. Then, you can use the `Suspense` component to render a fallback UI while the component is loading.
4.**Render The View Using The `stream_view_containing_react_components` Helper**
96
+
97
+
Ensure you have a controller that renders the view containing the React components. The controller must include the `ReactOnRails::Controller`, `ReactOnRailsPro::Stream` and `ActionController::Live` modules.
0 commit comments