Skip to content

Commit 0f80dd1

Browse files
authored
[Flight] Support concatenated modules in Webpack plugin (#20449)
* Extract recordModule * Add support for concatenated modules
1 parent daf38ec commit 0f80dd1

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js

+28-17
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,36 @@ export default class ReactFlightWebpackPlugin {
172172
const json = {};
173173
compilation.chunkGroups.forEach(chunkGroup => {
174174
const chunkIds = chunkGroup.chunks.map(c => c.id);
175+
176+
function recordModule(id, mod) {
177+
// TODO: Hook into deps instead of the target module.
178+
// That way we know by the type of dep whether to include.
179+
// It also resolves conflicts when the same module is in multiple chunks.
180+
if (!/\.client\.js$/.test(mod.resource)) {
181+
return;
182+
}
183+
const moduleExports = {};
184+
['', '*'].concat(mod.buildMeta.providedExports).forEach(name => {
185+
moduleExports[name] = {
186+
id: id,
187+
chunks: chunkIds,
188+
name: name,
189+
};
190+
});
191+
const href = pathToFileURL(mod.resource).href;
192+
if (href !== undefined) {
193+
json[href] = moduleExports;
194+
}
195+
}
196+
175197
chunkGroup.chunks.forEach(chunk => {
176198
chunk.getModules().forEach(mod => {
177-
// TODO: Hook into deps instead of the target module.
178-
// That way we know by the type of dep whether to include.
179-
// It also resolves conflicts when the same module is in multiple chunks.
180-
if (!/\.client\.js$/.test(mod.resource)) {
181-
return;
182-
}
183-
const moduleExports = {};
184-
['', '*'].concat(mod.buildMeta.providedExports).forEach(name => {
185-
moduleExports[name] = {
186-
id: mod.id,
187-
chunks: chunkIds,
188-
name: name,
189-
};
190-
});
191-
const href = pathToFileURL(mod.resource).href;
192-
if (href !== undefined) {
193-
json[href] = moduleExports;
199+
recordModule(mod.id, mod);
200+
// If this is a concatenation, register each child to the parent ID.
201+
if (mod.modules) {
202+
mod.modules.forEach(concatenatedMod => {
203+
recordModule(mod.id, concatenatedMod);
204+
});
194205
}
195206
});
196207
});

0 commit comments

Comments
 (0)