-
-
Notifications
You must be signed in to change notification settings - Fork 637
Add support for RSC #1644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add support for RSC #1644
Changes from all commits
Commits
Show all changes
105 commits
Select commit
Hold shift + click to select a range
ced9044
tmp
AbanoubGhadban 7710b68
tmp
AbanoubGhadban 6748c59
make rsc get the right rsc bundle path
AbanoubGhadban a5b936f
fix ts error after rebasing
AbanoubGhadban 0e69200
tmp
AbanoubGhadban f8a2cb9
DRY helper functions
AbanoubGhadban 97247d1
remove duplicate function
AbanoubGhadban cd96732
revert commiting some lines
AbanoubGhadban c0e5a55
refactor and add more tests for utils.rb
AbanoubGhadban 8f14356
add rsc_bundle_js_file config and update utils spec
AbanoubGhadban 86d0582
linting
AbanoubGhadban 4706e16
linting
AbanoubGhadban a70de09
don't set AsyncLocalStorage in global scope
AbanoubGhadban 14c6519
fix mock in webpack assets status checker test
AbanoubGhadban 263750f
mock that webpacker gem is not installed
AbanoubGhadban a667724
mock availablity of webpacker and shakapacker gems
AbanoubGhadban 32736d0
ensure that webpacker is not used when shakapacker in use in tests
AbanoubGhadban 5e01c8b
remove instance variables of PackerUtils on utils tests
AbanoubGhadban 3d2a73e
make utils rspec test run using the packer installed on CI
AbanoubGhadban 5987cb0
test bundle_js_file_path with webpacker and shakapacker
AbanoubGhadban 75421d6
linting
AbanoubGhadban fb60b55
remove webpacker test dependency
AbanoubGhadban 42b263e
don't mock gem availablity function
AbanoubGhadban b24ee8a
add rsc webpack loader
AbanoubGhadban f6df501
ignore whitespace when comparing scripts
Judahmeek c03589a
linting
AbanoubGhadban 025d3ca
Update knip config to add rsc entry points
AbanoubGhadban 5840117
Update knip config to use .js extension for RSCWebpackLoader
AbanoubGhadban 5bf7a87
linting
AbanoubGhadban 36e539f
[WIP] Hydrate components immediately after downloading chunks (#1656)
AbanoubGhadban ea42e81
Fix client startup rendering when the script runs after the page loaded
AbanoubGhadban fe2da15
Refactor client-side rendering and page lifecycle management
AbanoubGhadban 72978a2
Add component registry timeout configuration
AbanoubGhadban 3af4387
Refactor CallbackRegistry and clientStartup initialization
AbanoubGhadban e83901b
Update StoreRegistry error messages for clarity
AbanoubGhadban 7655f43
Fix RSC stream parsing to handle incomplete chunks
AbanoubGhadban 4308e4e
Refactor CallbackRegistry to improve item tracking and usage
AbanoubGhadban 38eafd2
Refactor CallbackRegistry and ComponentRegistry to simplify item trac…
AbanoubGhadban f9333ef
Update StoreRegistry test to use clearHydratedStores method
AbanoubGhadban c4f087b
Update RSC test to append newline to stream chunks
AbanoubGhadban c230617
don't strip the html chunk
AbanoubGhadban a018826
Add "use client" directive to RSCClientRoot
AbanoubGhadban b98b8a0
Convert RSCWebpackLoader to TypeScript
alexeyr e1cfc09
Comment on the need for workaround
alexeyr baa3a6a
Fix Knip
alexeyr 637c665
Simplify RSCWebpackLoader
alexeyr c1c9e78
remove rsc? and stream? render options and add render_mode option
AbanoubGhadban 8350954
Rename flight_payload_streaming to rsc_payload_streaming
AbanoubGhadban 9cc79eb
refactoring
AbanoubGhadban 907f190
Add async component retrieval and timeout handling to ComponentRegistry
AbanoubGhadban bc39925
add specs for packs generator
AbanoubGhadban fb66838
Update react_on_rails_helper_spec with new props added to component d…
AbanoubGhadban 0ce9498
Remove webpacker dependency from Gemfile.lock
AbanoubGhadban 9640fe8
Remove unnecessary webpacker mocking in configuration spec
AbanoubGhadban ea89406
Update package.json exports for React Server Components
AbanoubGhadban d56de7a
fix: don't trim html content on server
AbanoubGhadban 85467e3
Enable prerendering by default for React Server Components
AbanoubGhadban f5f145b
Rename RSC rendering methods and configuration to payload generation
AbanoubGhadban fb48ae6
add more comments for new components
AbanoubGhadban 2f5de75
linting
AbanoubGhadban dc905b2
Update package.json exports order for React Server Components
AbanoubGhadban d124fd8
remove prerender option for stream_react_component
AbanoubGhadban 3446864
small linting changes
AbanoubGhadban 1a19ddb
Use node 16 to run oldes tests
AbanoubGhadban d0c054c
Remove unnecessary data-store-dependencies attribute from test scripts
AbanoubGhadban 1d42a0f
linting
AbanoubGhadban 2215ed5
Convert loadReactClientManifest to async and update RSC rendering
AbanoubGhadban e162f8e
make RSCClientRoot tests compatible with React 19
AbanoubGhadban f80c948
Test fetch function only with node version 18+
AbanoubGhadban ad63a6f
pass props to RSC generator and avoid state reset on hydration
AbanoubGhadban 04d7309
Add ignore configuration for Knip static analysis
AbanoubGhadban e52613c
small changes
AbanoubGhadban a54b4cc
Implement stream buffering to safely handle stream events and errors
AbanoubGhadban e38f557
Fix stream error emission in buffered stream
AbanoubGhadban afdfeb5
Simplify streaming result parsing logic in server rendering
AbanoubGhadban a86dd9b
remove mentions to experiment react 18 and use only react 19
AbanoubGhadban 069a0e1
Refactor registerServerComponent into client and server modules
AbanoubGhadban 85f1974
Add RSCWebpackPlugin for React Server Components
AbanoubGhadban ebdc9c3
Replace react-server-dom-webpack with @shakacode-tools/react-on-rails…
AbanoubGhadban 1d590cd
Update TypeScript configuration and package dependencies for React Se…
AbanoubGhadban 453df4f
Remove webpack dependency from package configuration
AbanoubGhadban c525dac
Update @shakacode-tools/react-on-rails-rsc dependency to latest commit
AbanoubGhadban 005c29a
Make reactOnRailsPageLoaded async
AbanoubGhadban 280ba06
Update configuration to enable force_load by default and modify redux…
AbanoubGhadban 5eacb93
Bump version to 15.0.0-alpha.2 and update CHANGELOG
AbanoubGhadban d8460c4
revert this: Update package to use @abanoubghadban/react-on-rails-rsc
AbanoubGhadban b0173f1
Configure .npmrc for private GitHub package registry
AbanoubGhadban 4de5e78
Update import statements for path and fs modules in test file
AbanoubGhadban aec0357
Update test specs to add data-force-load attribute by default
AbanoubGhadban 6fd73e7
Add null check for ReactOnRails global object in component and store …
AbanoubGhadban f1d0964
Bump version to 15.0.0.alpha.2
AbanoubGhadban b1a3bbf
Update GitHub Actions workflows to use Shakacode Tools Packages Token
AbanoubGhadban 109293f
Update package to use @shakacode-tools/react-on-rails-rsc
AbanoubGhadban 233aefe
Revert version to 14.2.0 and update CHANGELOG
AbanoubGhadban 3b137fa
Enhance server-side rendering error logging and debugging
AbanoubGhadban 59359ae
Remove temporary debugging breakpoint in server rendering
AbanoubGhadban 61a0b6c
Revert gem version to 14.2.0 in Gemfile.lock
AbanoubGhadban fb69bf7
Remove backtrace from server rendering error logging
AbanoubGhadban 4eb472d
Update package to use react-on-rails-rsc package instead of the old p…
AbanoubGhadban eb1daef
Update CHANGELOG and knip configuration
AbanoubGhadban da1fa52
Change default defer behavior for generated component packs
AbanoubGhadban 6339773
Update test to reflect new default defer behavior for generated compo…
AbanoubGhadban 51e1341
Update CHANGELOG and release notes for React on Rails 15.0.0
AbanoubGhadban 4c5a0f2
Add domNodeId support for server-side rendering identifier prefix to …
AbanoubGhadban 018f404
Remove PR references from 15.0.0 release notes
AbanoubGhadban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,9 @@ jobs: | |
git config user.email "[email protected]" | ||
git config user.name "Your Name" | ||
git commit -am "stop generators from complaining about uncommitted code" | ||
- name: Set packer version environment variable | ||
run: | | ||
echo "CI_PACKER_VERSION=${{ matrix.versions == 'oldest' && 'old' || 'new' }}" >> $GITHUB_ENV | ||
- name: Run rspec tests | ||
run: bundle exec rspec spec/react_on_rails | ||
- name: Store test results | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# React on Rails 15.0.0 Release Notes | ||
|
||
## Major Features | ||
|
||
### 🚀 React Server Components Support | ||
Experience the future of React with full RSC integration in your Rails apps: | ||
- Seamlessly use React Server Components | ||
- Reduce client bundle sizes | ||
- Enable powerful new patterns for data fetching | ||
- ⚡️ Requires React on Rails Pro - [See the full tutorial](https://www.shakacode.com/react-on-rails-pro/docs/react-server-components-tutorial) | ||
|
||
### Improved Component Hydration | ||
Major improvements to component and store hydration: | ||
- Components and stores now hydrate immediately rather than waiting for page load | ||
- Enables faster hydration, especially beneficial for streamed pages | ||
- Components can hydrate before the page is fully streamed | ||
- Can use `async` scripts in the page with no fear of race condition | ||
- No need to use `defer` anymore | ||
|
||
## Breaking Changes | ||
|
||
### Component Hydration Changes | ||
- The `defer_generated_component_packs` and `force_load` configurations now default to `false` and `true` respectively. This means components will hydrate early without waiting for the full page load. This improves performance by eliminating unnecessary delays in hydration. | ||
- The previous need for deferring scripts to prevent race conditions has been eliminated due to improved hydration handling. Making scripts not defer is critical to execute the hydration scripts early before the page is fully loaded. | ||
- The `force_load` configuration make `react-on-rails` hydrate components immediately as soon as their server-rendered HTML reaches the client, without waiting for the full page load. | ||
- If you want to keep the previous behavior, you can set `defer_generated_component_packs: true` or `force_load: false` in your `config/initializers/react_on_rails.rb` file. | ||
- If we want to keep the original behavior of `force_load` for only one or more components, you can set `force_load: false` in the `react_component` helper or `force_load` configuration. | ||
- Redux store support `force_load` option now and it uses `config.force_load` value as the default value. Which means that the redux store will hydrate immediately as soon as its server-side data reaches the client. You can override this behavior for individual redux stores by setting `force_load: false` in the `redux_store` helper. | ||
|
||
- `ReactOnRails.reactOnRailsPageLoaded()` is now an async function: | ||
- If you are manually calling this function to ensure components are hydrated (e.g. with async script loading), you must now await the promise it returns: | ||
```js | ||
// Before | ||
ReactOnRails.reactOnRailsPageLoaded(); | ||
// Code expecting all components to be hydrated | ||
|
||
// After | ||
await ReactOnRails.reactOnRailsPageLoaded(); | ||
// Code expecting all components to be hydrated | ||
``` | ||
|
||
## Store Dependencies for Components | ||
|
||
When using Redux stores with multiple components, you need to explicitly declare store dependencies to optimize hydration. Here's how: | ||
|
||
### The Problem | ||
|
||
If you have deferred Redux stores and components like this: | ||
|
||
```erb | ||
<% redux_store("SimpleStore", props: @app_props_server_render, defer: true) %> | ||
<%= react_component('ReduxApp', {}, {prerender: true}) %> | ||
<%= react_component('ComponentWithNoStore', {}, {prerender: true}) %> | ||
<%= redux_store_hydration_data %> | ||
``` | ||
|
||
By default, React on Rails assumes components depend on all previously created stores. This means: | ||
- Neither `ReduxApp` nor `ComponentWithNoStore` will hydrate until `SimpleStore` is hydrated | ||
- Since the store is deferred to the end of the page, both components are forced to wait unnecessarily | ||
|
||
### The Solution | ||
|
||
Explicitly declare store dependencies for each component: | ||
|
||
```erb | ||
<% redux_store("SimpleStore", props: @app_props_server_render, defer: true) %> | ||
<%= react_component('ReduxApp', {}, { | ||
prerender: true | ||
<!-- No need to specify store_dependencies - it automatically depends on SimpleStore --> | ||
}) %> | ||
<%= react_component('ComponentWithNoStore', {}, { | ||
prerender: true, | ||
store_dependencies: [] <!-- Explicitly declare no store dependencies --> | ||
}) %> | ||
<%= redux_store_hydration_data %> | ||
``` | ||
|
||
This allows `ComponentWithNoStore` to hydrate immediately without waiting for `SimpleStore`, improving page performance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
const nodeVersion = parseInt(process.version.slice(1), 10); | ||
|
||
module.exports = { | ||
preset: 'ts-jest/presets/js-with-ts', | ||
testEnvironment: 'jsdom', | ||
setupFiles: ['<rootDir>/node_package/tests/jest.setup.js'], | ||
// React Server Components tests are compatible with React 19 | ||
// That only run with node version 18 and above | ||
moduleNameMapper: | ||
nodeVersion < 18 | ||
? { | ||
'react-on-rails-rsc/client': '<rootDir>/node_package/tests/emptyForTesting.js', | ||
'^@testing-library/dom$': '<rootDir>/node_package/tests/emptyForTesting.js', | ||
'^@testing-library/react$': '<rootDir>/node_package/tests/emptyForTesting.js', | ||
} | ||
: {}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.