Skip to content

Commit 4d9d19e

Browse files
justin808claude
andcommitted
Fix CSS plugin filtering and add cache immutability docs
CSS Plugin Filtering Improvements: 1. Added CssExtractRspackPlugin to plugin filter list (line 95) - Ensures Rspack's CSS plugin is properly removed from SSR bundle - Previously only filtered MiniCssExtractPlugin (Webpack) 2. Enhanced loader filtering with explicit Rspack check (lines 114-119) - Added regex match for CssExtractRspackPlugin - Ensures both Webpack and Rspack CSS loaders are filtered Cache Immutability Documentation: - Added detailed comment explaining Shakapacker config immutability - Clarifies that config is loaded once at Node process start - Documents that cache is safe because config cannot change at runtime These changes address potential edge cases when using Rspack for SSR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2af9d6f commit 4d9d19e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

config/webpack/bundlerUtils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ const { config } = require('shakapacker');
1010

1111
const VALID_BUNDLERS = ['webpack', 'rspack'];
1212

13-
// Cache for bundler module (config is read at startup and cannot change without restart)
13+
// Cache for bundler module
14+
// IMPORTANT: Shakapacker config is immutable at runtime - it's loaded once when the
15+
// Node process starts. Changing shakapacker.yml requires restarting the server.
16+
// This cache is safe because config.assets_bundler cannot change during execution.
1417
let _cachedBundler = null;
1518
let _cachedBundlerType = null;
1619

config/webpack/serverWebpackConfig.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ const configureServer = () => {
8787
};
8888

8989
// Don't hash the server bundle b/c would conflict with the client manifest
90-
// And no need for the MiniCssExtractPlugin
90+
// And no need for CSS extraction plugins (MiniCssExtractPlugin or CssExtractRspackPlugin)
9191
serverWebpackConfig.plugins = serverWebpackConfig.plugins.filter(
9292
(plugin) =>
9393
plugin.constructor.name !== 'WebpackAssetsManifest' &&
9494
plugin.constructor.name !== 'MiniCssExtractPlugin' &&
95+
plugin.constructor.name !== 'CssExtractRspackPlugin' &&
9596
plugin.constructor.name !== 'ForkTsCheckerWebpackPlugin',
9697
);
9798

@@ -110,7 +111,12 @@ const configureServer = () => {
110111
} else if (typeof item.loader === 'string') {
111112
testValue = item.loader;
112113
}
113-
return !(testValue?.match(/mini-css-extract-plugin/) || testValue?.includes('cssExtractLoader') || testValue === 'style-loader');
114+
return !(
115+
testValue?.match(/mini-css-extract-plugin/) ||
116+
testValue?.match(/CssExtractRspackPlugin/) ||
117+
testValue?.includes('cssExtractLoader') ||
118+
testValue === 'style-loader'
119+
);
114120
});
115121
const cssLoader = rule.use.find((item) => {
116122
let testValue;

0 commit comments

Comments
 (0)