Repository navigation
Description
Summary
When a Webpack chunk's files set starts with a non-JavaScript asset (such as extracted CSS from mini-css-extract-plugin) or a .hot-update.* file, ReactFlightWebpackPlugin aborts processing that entire chunk and leaves the component's Flight client manifest entry with chunks: [], even though Webpack still emits the chunk's JavaScript file (e.g., client0.js).
Affected version
[email protected],[email protected],[email protected],[email protected](reproduced identically in bothdevelopmentandproductionmodes on Node.jsv22.22.2andv24.22.1)- Verified unchanged on
mainatedae846a9a17442c00429f2b15375afbfa0376c9
Impact
The trigger is any non-JavaScript asset (or .hot-update.* file) appearing before the runtime .js/.mjs file in chunk.files — mini-css-extract-plugin is just a common way to produce that ordering, not a bug in mini-css-extract-plugin. Because the Flight client manifest entry ends up with chunks: [], a Flight client relying on the manifest has no chunk ID or JS filename to preload/load for that client reference.
Reproduction
In an empty directory:
npm install [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
cat <<'JS' > build.cjs
const fs = require('node:fs');
const path = require('node:path');
const webpack = require('webpack');
const MiniCss = require('mini-css-extract-plugin');
const Flight = require('react-server-dom-webpack/plugin');
fs.writeFileSync('entry.js', "import 'react-server-dom-webpack/client.browser';");
fs.writeFileSync('Client.js', "'use client'; import './client.css'; export default () => null;");
fs.writeFileSync('client.css', 'body { color: navy; }');
const compiler = webpack({
mode: 'development',
entry: './entry.js',
output: {path: path.resolve('dist'), publicPath: '/'},
module: {rules: [{test: /\.css$/, use: [MiniCss.loader, 'css-loader']}]},
plugins: [
new MiniCss(),
new Flight({isServer: false, clientReferences: path.resolve('Client.js')}),
],
});
compiler.run((err, stats) => {
if (err || stats.hasErrors()) throw err || new Error(stats.toString({all: false, errors: true}));
for (const c of stats.compilation.chunks) {
if (c.name !== 'main') console.log([...c.files]);
}
console.log(JSON.parse(fs.readFileSync('dist/react-client-manifest.json', 'utf8')));
compiler.close(() => {});
});
JS
node build.cjsActual output
[ 'client0.css', 'client0.js' ]
{
'file:///.../Client.js': { id: './Client.js', chunks: [], name: '*' }
}
The same empty chunks: [] result reproduces with mode: 'production' (with a numeric module id).
Expected behavior
The manifest entry should still record the chunk's JavaScript file regardless of asset order in c.files:
{
'file:///.../Client.js': { id: './Client.js', chunks: [ 'client0', 'client0.js' ], name: '*' }
}
(Chunks containing only non-JavaScript assets with no .js/.mjs file should of course still produce chunks: [], since the manifest records JS chunks only.)
Related
- Related:
#33155/ PR#33028updated this same loop to accept.mjsfiles. This issue is the asset-ordering bug in the same loop: any non-JS or.hot-update.*file appearing first inc.filesexits the chunk callback early.
Root cause and suggested fix
In ReactFlightWebpackPlugin.js#L277-L291, both guards inside the for (const file of c.files) loop use return; (#L281 and #L287), returning out of the entire chunkGroup.chunks.forEach callback instead of skipping to the next file:
chunkGroup.chunks.forEach(function (c) {
for (const file of c.files) {
if (!(file.endsWith('.js') || file.endsWith('.mjs'))) {
continue; // was: return;
}
if (
file.endsWith('.hot-update.js') ||
file.endsWith('.hot-update.mjs')
)
continue; // was: return;
chunks.push(c.id, file);
break;
}
});Changing both return; statements to continue; while keeping break; after chunks.push(c.id, file) (#L289) fixes both dev and production builds (verified locally against [email protected], yielding chunks: [ 'client0', 'client0.js' ]).
Activity