Skip to content

RSC manifest omits chunks when CSS files precede JS in chunk.files Set #27

@AbanoubGhadban

Description

@AbanoubGhadban

Bug

The ReactFlightWebpackPlugin (vendored from react-server-dom-webpack) silently drops chunks from the client manifest (react-client-manifest.json) when a chunk contains both .css and .js files and the .css file is iterated first in the chunk's files Set.

Root Cause

In the processAssets hook, the plugin iterates c.files using a for...of loop inside a forEach callback:

chunkGroup.chunks.forEach(function (c) {
    for (const file of c.files) {
        if (!file.endsWith('.js')) break;       // ← BUG: exits entire loop
        if (file.endsWith('.hot-update.js')) break;
        chunks.push(c.id, file);
        break;
    }
});

The first break (compiled from return in the React source) is intended to skip non-JS files and try the next file. But break exits the for loop entirely (and return in the source exits the forEach callback), so when a .css file appears before the .js file in the Set iteration order, the .js file is never examined. The chunk is completely omitted from the manifest.

Impact

  • The client manifest's chunks array is empty for affected modules
  • The RSC Flight runtime can't locate client components → RSC fails silently or errors at hydration
  • The bug is non-deterministic: it depends on Set insertion order, which varies across webpack versions and environments
  • Triggered by mini-css-extract-plugin or any loader that produces .css chunk files alongside .js

Fix

Change break to continue (compiled) / return to continue (source) for the two skip conditions:

// Fixed:
for (const file of c.files) {
    if (!file.endsWith('.js')) continue;           // skip non-JS, try next file
    if (file.endsWith('.hot-update.js')) continue;  // skip HMR, try next file
    chunks.push(c.id, file);
    break;                                          // found JS file, done
}

Fix Commit

The fix has been applied to the React fork:
AbanoubGhadban/react@8b6dec4

Branch: fix/flight-plugin-css-chunk-skip (based on rsc-patches/v19.0.3)

Upstream

This is an upstream bug in facebook/react, introduced in commit 701ac2e5 (PR #27314, Sep 2023) and still unfixed on main as of March 2026. Next.js is unaffected because they wrote their own plugin using nested forEach (where return naturally acts as continue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions