Skip to content

Commit bf8b715

Browse files
justin808claude
andcommitted
Fix React 19 webpack server bundle resolution and update docs
This commit addresses two issues identified in CI: 1. **Markdown link check failure**: Updated the ShakaCode contact link in react-19-quick-reference.md from https://www.shakacode.com/contact to mailto:justin@shakacode.com to fix the 404 error. 2. **Webpack server bundle build errors**: Fixed React 19 compatibility issue where the server bundle was incorrectly resolving React to the react-server condition, causing missing exports for createContext, useContext, and Component. **Changes:** - Update contact link in docs/upgrading/react-19-quick-reference.md - Add explicit conditionNames configuration to all serverWebpackConfig.js files to prevent resolving to react-server build (only RSC bundles should use that) - Disable react/react-in-jsx-scope ESLint rule since React 17+ uses new JSX transform **Technical Details:** React 19 introduced conditional package exports with a react-server condition. When webpack targets 'node' for SSR bundles, it may include react-server in its default conditionNames, causing client components with hooks to fail. The fix explicitly sets conditionNames to ['node', 'require', 'import', '...'] to use the standard React build. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 792d9fb commit bf8b715

File tree

6 files changed

+36
-1
lines changed

6 files changed

+36
-1
lines changed

docs/upgrading/react-19-quick-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ bin/rails assets:precompile
169169
- [Full React 19 Upgrade Guide](./react-19-upgrade-guide.md)
170170
- [React on Rails Issues](https://github.com/shakacode/react_on_rails/issues)
171171
- [ShakaCode Forum](https://forum.shakacode.com)
172-
- [Commercial Support](https://www.shakacode.com/contact)
172+
- [Commercial Support](mailto:justin@shakacode.com)

eslint.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ const config = tsEslint.config([
9797
// Custom React on Rails rules
9898
'react-on-rails/no-use-client-in-server-files': 'error',
9999

100+
// React 17+ with new JSX transform doesn't require React in scope
101+
'react/react-in-jsx-scope': 'off',
102+
100103
'no-shadow': 'off',
101104
'no-console': 'off',
102105
'function-paren-newline': 'off',

lib/generators/react_on_rails/templates/base/base/config/webpack/serverWebpackConfig.js.tt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ const configureServer = () => {
114114
// If using the React on Rails Pro node server renderer, uncomment the next line
115115
// serverWebpackConfig.target = 'node'
116116

117+
// React 19 Fix: Explicitly set conditionNames to prevent resolving to react-server build
118+
// The server bundle should use the regular React build, not the react-server build
119+
// Only the RSC bundle should use react-server condition
120+
if (!serverWebpackConfig.resolve) {
121+
serverWebpackConfig.resolve = {};
122+
}
123+
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
124+
117125
return serverWebpackConfig;
118126
};
119127

react_on_rails_pro/spec/dummy/config/webpack/serverWebpackConfig.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ const configureServer = (rscBundle = false) => {
123123

124124
serverWebpackConfig.node = false;
125125

126+
// React 19 Fix: Explicitly set conditionNames to prevent resolving to react-server build
127+
// The server bundle should use the regular React build, not the react-server build
128+
// Only the RSC bundle should use react-server condition
129+
if (!serverWebpackConfig.resolve) {
130+
serverWebpackConfig.resolve = {};
131+
}
132+
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
133+
126134
return serverWebpackConfig;
127135
};
128136

react_on_rails_pro/spec/execjs-compatible-dummy/config/webpack/serverWebpackConfig.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ const configureServer = () => {
112112
// If using the React on Rails Pro node server renderer, uncomment the next line
113113
// serverWebpackConfig.target = 'node'
114114

115+
// React 19 Fix: Explicitly set conditionNames to prevent resolving to react-server build
116+
// The server bundle should use the regular React build, not the react-server build
117+
// Only the RSC bundle should use react-server condition
118+
if (!serverWebpackConfig.resolve) {
119+
serverWebpackConfig.resolve = {};
120+
}
121+
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
122+
115123
return serverWebpackConfig;
116124
};
117125

spec/dummy/config/webpack/serverWebpackConfig.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ const configureServer = () => {
110110
// If using the React on Rails Pro node server renderer, uncomment the next line
111111
// serverWebpackConfig.target = 'node'
112112

113+
// React 19 Fix: Explicitly set conditionNames to prevent resolving to react-server build
114+
// The server bundle should use the regular React build, not the react-server build
115+
// Only the RSC bundle should use react-server condition
116+
if (!serverWebpackConfig.resolve) {
117+
serverWebpackConfig.resolve = {};
118+
}
119+
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
120+
113121
return serverWebpackConfig;
114122
};
115123

0 commit comments

Comments
 (0)