Skip to content

Commit 7c35cdb

Browse files
justin808claude
andcommitted
Fix React 19 webpack conditionNames to prevent react-server resolution
This fixes the webpack server bundle build errors where React was incorrectly resolving to the react-server condition, causing missing exports for hooks and Component class. **Problem:** - React 19 introduced conditional package exports with react-server condition - Webpack 5 with target: 'node' was including react-server in conditionNames - This caused RSCProvider/RSCRoute client components to fail with missing createContext, useContext, and Component exports **Solution:** - Explicitly set resolve.conditionNames to ['node', 'import', 'require', 'default'] - This matches webpack's defaults for node target but excludes react-server - Server bundles now correctly use the full React build with hooks **Changes:** - Updated all serverWebpackConfig.js files to set explicit conditionNames - Only RSC bundles should use react-server condition, not server-bundles 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e417b5f commit 7c35cdb

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ 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
117+
// React 19 Fix: Prevent webpack from resolving to react-server condition
118+
// The server-bundle needs the full React with hooks for SSR, not the react-server build
119+
// Explicitly set conditionNames without react-server
120120
if (!serverWebpackConfig.resolve) {
121121
serverWebpackConfig.resolve = {};
122122
}
123-
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
123+
// For target: 'node', webpack defaults to ['node', 'import', 'require', 'default']
124+
// We explicitly list them to ensure react-server is not included
125+
serverWebpackConfig.resolve.conditionNames = ['node', 'import', 'require', 'default'];
124126

125127
return serverWebpackConfig;
126128
};

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,15 @@ 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
126+
// React 19 Fix: Prevent webpack from resolving to react-server condition
127+
// The server-bundle needs the full React with hooks for SSR, not the react-server build
128+
// Explicitly set conditionNames without react-server
129129
if (!serverWebpackConfig.resolve) {
130130
serverWebpackConfig.resolve = {};
131131
}
132-
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
132+
// For target: 'node', webpack defaults to ['node', 'import', 'require', 'default']
133+
// We explicitly list them to ensure react-server is not included
134+
serverWebpackConfig.resolve.conditionNames = ['node', 'import', 'require', 'default'];
133135

134136
return serverWebpackConfig;
135137
};

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ 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
115+
// React 19 Fix: Prevent webpack from resolving to react-server condition
116+
// The server-bundle needs the full React with hooks for SSR, not the react-server build
117+
// Explicitly set conditionNames without react-server
118118
if (!serverWebpackConfig.resolve) {
119119
serverWebpackConfig.resolve = {};
120120
}
121-
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
121+
// For target: 'node', webpack defaults to ['node', 'import', 'require', 'default']
122+
// We explicitly list them to ensure react-server is not included
123+
serverWebpackConfig.resolve.conditionNames = ['node', 'import', 'require', 'default'];
122124

123125
return serverWebpackConfig;
124126
};

spec/dummy/config/webpack/serverWebpackConfig.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ 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
113+
// React 19 Fix: Prevent webpack from resolving to react-server condition
114+
// The server-bundle needs the full React with hooks for SSR, not the react-server build
115+
// Explicitly set conditionNames without react-server
116116
if (!serverWebpackConfig.resolve) {
117117
serverWebpackConfig.resolve = {};
118118
}
119-
serverWebpackConfig.resolve.conditionNames = ['node', 'require', 'import', '...'];
119+
// For target: 'node', webpack defaults to ['node', 'import', 'require', 'default']
120+
// We explicitly list them to ensure react-server is not included
121+
serverWebpackConfig.resolve.conditionNames = ['node', 'import', 'require', 'default'];
120122

121123
return serverWebpackConfig;
122124
};

0 commit comments

Comments
 (0)