From 1b63456814d425fe3b2c6d15ec6fca13a47663cf Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 12 Dec 2020 18:29:25 +0000 Subject: [PATCH 1/2] Extract recordModule --- .../src/ReactFlightWebpackPlugin.js | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js b/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js index a1957692b7e74..adf3f09dd2478 100644 --- a/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js +++ b/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js @@ -172,26 +172,31 @@ export default class ReactFlightWebpackPlugin { const json = {}; compilation.chunkGroups.forEach(chunkGroup => { const chunkIds = chunkGroup.chunks.map(c => c.id); + + function recordModule(id, mod) { + // TODO: Hook into deps instead of the target module. + // That way we know by the type of dep whether to include. + // It also resolves conflicts when the same module is in multiple chunks. + if (!/\.client\.js$/.test(mod.resource)) { + return; + } + const moduleExports = {}; + ['', '*'].concat(mod.buildMeta.providedExports).forEach(name => { + moduleExports[name] = { + id: mod.id, + chunks: chunkIds, + name: name, + }; + }); + const href = pathToFileURL(mod.resource).href; + if (href !== undefined) { + json[href] = moduleExports; + } + } + chunkGroup.chunks.forEach(chunk => { chunk.getModules().forEach(mod => { - // TODO: Hook into deps instead of the target module. - // That way we know by the type of dep whether to include. - // It also resolves conflicts when the same module is in multiple chunks. - if (!/\.client\.js$/.test(mod.resource)) { - return; - } - const moduleExports = {}; - ['', '*'].concat(mod.buildMeta.providedExports).forEach(name => { - moduleExports[name] = { - id: mod.id, - chunks: chunkIds, - name: name, - }; - }); - const href = pathToFileURL(mod.resource).href; - if (href !== undefined) { - json[href] = moduleExports; - } + recordModule(mod.id, mod); }); }); }); From 3995639d517d80e3fab950ff400e64c131ab218f Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 12 Dec 2020 18:29:39 +0000 Subject: [PATCH 2/2] Add support for concatenated modules --- .../src/ReactFlightWebpackPlugin.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js b/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js index adf3f09dd2478..eb8c489d394d5 100644 --- a/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js +++ b/packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js @@ -183,7 +183,7 @@ export default class ReactFlightWebpackPlugin { const moduleExports = {}; ['', '*'].concat(mod.buildMeta.providedExports).forEach(name => { moduleExports[name] = { - id: mod.id, + id: id, chunks: chunkIds, name: name, }; @@ -197,6 +197,12 @@ export default class ReactFlightWebpackPlugin { chunkGroup.chunks.forEach(chunk => { chunk.getModules().forEach(mod => { recordModule(mod.id, mod); + // If this is a concatenation, register each child to the parent ID. + if (mod.modules) { + mod.modules.forEach(concatenatedMod => { + recordModule(mod.id, concatenatedMod); + }); + } }); }); });