Skip to content

Commit d527ddf

Browse files
Move Pro-specific utilities and configurations to Pro gem (#1875)
Migrates React Server Components (RSC) and streaming SSR functionality from the open-source gem to the Pro gem, establishing clear separation between free and commercial features. Changes: - Phase 1: Updated documentation to reflect Pro-only RSC/streaming features - Phase 2: Moved RSC configs to ReactOnRailsPro.configure block - Phase 3: Migrated RSC utility methods to ReactOnRailsPro::Utils - Phase 4: Moved streaming helper methods to ReactOnRailsPro::Helper
1 parent 64dc33a commit d527ddf

File tree

25 files changed

+723
-595
lines changed

25 files changed

+723
-595
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ ssr-generated
7575

7676
# Claude Code local settings
7777
.claude/settings.local.json
78+
.claude/.fuse_hidden*

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,39 @@ To migrate to React on Rails Pro:
7373

7474
**Note:** If you're not using any of the Pro-only methods listed above, no changes are required.
7575

76+
- **Pro-Specific Configurations Moved to Pro Gem**: The following React Server Components (RSC) configurations have been moved from `ReactOnRails.configure` to `ReactOnRailsPro.configure`:
77+
78+
- `rsc_bundle_js_file` - Path to the RSC bundle file
79+
- `react_server_client_manifest_file` - Path to the React server client manifest
80+
- `react_client_manifest_file` - Path to the React client manifest
81+
82+
**Migration:** If you're using RSC features, move these configurations from your `ReactOnRails.configure` block to `ReactOnRailsPro.configure`:
83+
84+
```ruby
85+
# Before
86+
ReactOnRails.configure do |config|
87+
config.rsc_bundle_js_file = "rsc-bundle.js"
88+
config.react_server_client_manifest_file = "react-server-client-manifest.json"
89+
config.react_client_manifest_file = "react-client-manifest.json"
90+
end
91+
92+
# After
93+
ReactOnRailsPro.configure do |config|
94+
config.rsc_bundle_js_file = "rsc-bundle.js"
95+
config.react_server_client_manifest_file = "react-server-client-manifest.json"
96+
config.react_client_manifest_file = "react-client-manifest.json"
97+
end
98+
```
99+
100+
See the [React on Rails Pro Configuration docs](https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/configuration.md) for more details.
101+
102+
- **Streaming View Helpers Moved to Pro Gem**: The following view helpers have been removed from the open-source gem and are now only available in React on Rails Pro:
103+
104+
- `stream_react_component` - Progressive SSR using React 18+ streaming
105+
- `rsc_payload_react_component` - RSC payload rendering
106+
107+
These helpers are now defined exclusively in the `react-on-rails-pro` gem.
108+
76109
### [16.1.1] - 2025-09-24
77110

78111
#### Bug Fixes

docs/api-reference/configuration.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,30 +104,21 @@ ReactOnRails.configure do |config|
104104
# you should include a name that matches your bundle name in your Webpack config.
105105
config.server_bundle_js_file = "server-bundle.js"
106106

107-
# When using React on Rails Pro with RSC support enabled, these configuration options work together:
108-
#
109-
# 1. In RORP, set `config.enable_rsc_support = true` in your react_on_rails_pro.rb initializer
110-
#
111-
# 2. The `rsc_bundle_js_file` (typically "rsc-bundle.js") contains only server components and
112-
# references to client components. It's generated using the RSC Webpack Loader which transforms
113-
# client components into references. This bundle is specifically used for generating RSC payloads
114-
# and is configured with the `react-server` condition.
115-
config.rsc_bundle_js_file = "rsc-bundle.js"
107+
################################################################################
108+
# REACT SERVER COMPONENTS (RSC) AND STREAMING CONFIGURATION
109+
################################################################################
116110
#
117-
# 3. The `react_client_manifest_file` contains mappings for client components that need hydration.
118-
# It's generated by the React Server Components Webpack plugin and is required for client-side
119-
# hydration of components.
120-
# This manifest file is automatically generated by the React Server Components Webpack plugin. Only set this if you've configured the plugin to use a different filename.
121-
config.react_client_manifest_file = "react-client-manifest.json"
111+
# React Server Components and Streaming SSR are React on Rails Pro features.
112+
# For detailed configuration of RSC and streaming features, see:
113+
# https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/configuration.md
122114
#
123-
# 4. The `react_server_client_manifest_file` is used during server-side rendering with RSC to
124-
# properly resolve references between server and client components.
115+
# Key Pro configurations (configured in ReactOnRailsPro.configure block):
116+
# - rsc_bundle_js_file: Path to RSC bundle
117+
# - react_client_manifest_file: Client component manifest for RSC
118+
# - react_server_client_manifest_file: Server manifest for RSC
119+
# - enable_rsc_support: Enable React Server Components
125120
#
126-
# These files are crucial when implementing React Server Components with streaming, which offers
127-
# benefits like reduced JavaScript bundle sizes, faster page loading, and selective hydration
128-
# of client components.
129-
# This manifest file is automatically generated by the React Server Components Webpack plugin. Only set this if you've configured the plugin to use a different filename.
130-
config.react_server_client_manifest_file = "react-server-client-manifest.json"
121+
# See Pro documentation for complete setup instructions.
131122

132123
################################################################################
133124
# SERVER BUNDLE SECURITY AND ORGANIZATION

docs/api-reference/view-helpers-api.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,6 @@ export default (props, _railsContext) => {
8080

8181
---
8282

83-
### cached_react_component and cached_react_component_hash
84-
85-
Fragment caching is a [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki) feature. The API is the same as the above, but for 2 differences:
86-
87-
1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
88-
1. The **props** are passed via a block so that evaluation of the props is not done unless the cache is broken. Suppose you put your props calculation into some method called `some_slow_method_that_returns_props`:
89-
90-
```erb
91-
<%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
92-
some_slow_method_that_returns_props
93-
end %>
94-
```
95-
96-
---
97-
9883
### rails_context
9984

10085
You can call `rails_context` or `rails_context(server_side: true|false)` from your controller or view to see what values are in the Rails Context. Pass true or false depending on whether you want to see the server-side or the client-side `rails_context`. Typically, for computing cache keys, you should leave `server_side` as the default true. When calling this from a controller method, use `helpers.rails_context`.
@@ -132,6 +117,47 @@ This is a helper method that takes any JavaScript expression and returns the out
132117

133118
---
134119

120+
## Pro-Only View Helpers
121+
122+
The following view helpers are available exclusively with [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro). These require a valid React on Rails Pro license and will not be available if the Pro gem is not installed or properly licensed.
123+
124+
### cached_react_component and cached_react_component_hash
125+
126+
Fragment caching helpers that cache React component rendering to improve performance. The API is the same as `react_component` and `react_component_hash`, but with these differences:
127+
128+
1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
129+
2. The **props** are passed via a block so that evaluation of the props is not done unless the cache is broken.
130+
131+
Example usage:
132+
133+
```erb
134+
<%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
135+
some_slow_method_that_returns_props
136+
end %>
137+
```
138+
139+
### stream_react_component
140+
141+
Progressive server-side rendering using React 18+ streaming with `renderToPipeableStream`. This enables:
142+
143+
- Faster Time to First Byte (TTFB)
144+
- Progressive page loading with Suspense boundaries
145+
- Better perceived performance
146+
147+
See the [Streaming Server Rendering guide](../building-features/streaming-server-rendering.md) for usage details.
148+
149+
### rsc_payload_react_component
150+
151+
Renders React Server Component (RSC) payloads in NDJSON format for client-side consumption. Used in conjunction with RSC support to enable:
152+
153+
- Reduced JavaScript bundle sizes
154+
- Server-side data fetching
155+
- Selective client-side hydration
156+
157+
See the [React on Rails Pro Configuration](https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/configuration.md) for RSC setup.
158+
159+
---
160+
135161
# More details
136162

137163
See the [lib/react_on_rails/helper.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb) source.

lib/react_on_rails/configuration.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def self.configure
99
end
1010

1111
DEFAULT_GENERATED_ASSETS_DIR = File.join(%w[public webpack], Rails.env).freeze
12-
DEFAULT_REACT_CLIENT_MANIFEST_FILE = "react-client-manifest.json"
13-
DEFAULT_REACT_SERVER_CLIENT_MANIFEST_FILE = "react-server-client-manifest.json"
1412
DEFAULT_COMPONENT_REGISTRY_TIMEOUT = 5000
1513

1614
def self.configuration
@@ -20,9 +18,6 @@ def self.configuration
2018
# generated_assets_dirs is deprecated
2119
generated_assets_dir: "",
2220
server_bundle_js_file: "",
23-
rsc_bundle_js_file: "",
24-
react_client_manifest_file: DEFAULT_REACT_CLIENT_MANIFEST_FILE,
25-
react_server_client_manifest_file: DEFAULT_REACT_SERVER_CLIENT_MANIFEST_FILE,
2621
prerender: false,
2722
auto_load_bundle: false,
2823
replay_console: true,
@@ -72,8 +67,8 @@ class Configuration
7267
:server_render_method, :random_dom_id, :auto_load_bundle,
7368
:same_bundle_for_client_and_server, :rendering_props_extension,
7469
:make_generated_server_bundle_the_entrypoint,
75-
:generated_component_packs_loading_strategy, :immediate_hydration, :rsc_bundle_js_file,
76-
:react_client_manifest_file, :react_server_client_manifest_file, :component_registry_timeout,
70+
:generated_component_packs_loading_strategy, :immediate_hydration,
71+
:component_registry_timeout,
7772
:server_bundle_output_path, :enforce_private_server_bundles
7873

7974
# rubocop:disable Metrics/AbcSize
@@ -90,7 +85,6 @@ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender
9085
i18n_dir: nil, i18n_yml_dir: nil, i18n_output_format: nil, i18n_yml_safe_load_options: nil,
9186
random_dom_id: nil, server_render_method: nil, rendering_props_extension: nil,
9287
components_subdirectory: nil, auto_load_bundle: nil, immediate_hydration: nil,
93-
rsc_bundle_js_file: nil, react_client_manifest_file: nil, react_server_client_manifest_file: nil,
9488
component_registry_timeout: nil, server_bundle_output_path: nil, enforce_private_server_bundles: nil)
9589
self.node_modules_location = node_modules_location.present? ? node_modules_location : Rails.root
9690
self.generated_assets_dirs = generated_assets_dirs
@@ -119,9 +113,6 @@ def initialize(node_modules_location: nil, server_bundle_js_file: nil, prerender
119113

120114
# Server rendering:
121115
self.server_bundle_js_file = server_bundle_js_file
122-
self.rsc_bundle_js_file = rsc_bundle_js_file
123-
self.react_client_manifest_file = react_client_manifest_file
124-
self.react_server_client_manifest_file = react_server_client_manifest_file
125116
self.same_bundle_for_client_and_server = same_bundle_for_client_and_server
126117
self.server_renderer_pool_size = self.development_mode ? 1 : server_renderer_pool_size
127118
self.server_renderer_timeout = server_renderer_timeout # seconds

0 commit comments

Comments
 (0)