Skip to content

Commit 8c234c0

Browse files
authored
Move the Webpack manifest config to one level deeper (#26083)
This frees up the Webpack manifest to contain a `serverManifest` part too. @shuding
1 parent 977bccd commit 8c234c0

File tree

7 files changed

+22
-19
lines changed

7 files changed

+22
-19
lines changed

fixtures/flight/server/handler.server.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ module.exports = function (req, res) {
2020
const App = m.default.default || m.default;
2121
res.setHeader('Access-Control-Allow-Origin', '*');
2222
const moduleMap = JSON.parse(data);
23-
const {pipe} = renderToPipeableStream(
24-
React.createElement(App),
25-
moduleMap
26-
);
23+
const {pipe} = renderToPipeableStream(React.createElement(App), {
24+
clientManifest: moduleMap,
25+
});
2726
pipe(res);
2827
}
2928
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ type Options = {
2727

2828
function renderToReadableStream(
2929
model: ReactModel,
30-
webpackMap: BundlerConfig,
30+
webpackMaps: BundlerConfig,
3131
options?: Options,
3232
): ReadableStream {
3333
const request = createRequest(
3434
model,
35-
webpackMap,
35+
webpackMaps,
3636
options ? options.onError : undefined,
3737
options ? options.context : undefined,
3838
options ? options.identifierPrefix : undefined,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ type PipeableStream = {
3737

3838
function renderToPipeableStream(
3939
model: ReactModel,
40-
webpackMap: BundlerConfig,
40+
webpackMaps: BundlerConfig,
4141
options?: Options,
4242
): PipeableStream {
4343
const request = createRequest(
4444
model,
45-
webpackMap,
45+
webpackMaps,
4646
options ? options.onError : undefined,
4747
options ? options.context : undefined,
4848
options ? options.identifierPrefix : undefined,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ type WebpackMap = {
1313
},
1414
};
1515

16-
export type BundlerConfig = WebpackMap;
16+
export type BundlerConfig = {
17+
clientManifest: WebpackMap,
18+
};
1719

1820
// eslint-disable-next-line no-unused-vars
1921
export type ClientReference<T> = {
@@ -54,7 +56,7 @@ export function resolveModuleMetaData<T>(
5456
clientReference: ClientReference<T>,
5557
): ModuleMetaData {
5658
const resolvedModuleData =
57-
config[clientReference.filepath][clientReference.name];
59+
config.clientManifest[clientReference.filepath][clientReference.name];
5860
if (clientReference.async) {
5961
return {
6062
id: resolvedModuleData.id,

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ describe('ReactFlightDOM', () => {
848848
});
849849

850850
// We simulate a bug in the Webpack bundler which causes an error on the server.
851-
for (const id in webpackMap) {
852-
Object.defineProperty(webpackMap, id, {
851+
for (const id in webpackMap.clientManifest) {
852+
Object.defineProperty(webpackMap.clientManifest, id, {
853853
get: () => {
854854
throw new Error('bug in the bundler');
855855
},

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,14 @@ describe('ReactFlightDOMBrowser', () => {
473473
const ClientComponentOnTheServer = clientExports(ClientComponent);
474474

475475
// In the SSR bundle this module won't exist. We simulate this by deleting it.
476-
const clientId = webpackMap[ClientComponentOnTheClient.filepath]['*'].id;
476+
const clientId =
477+
webpackMap.clientManifest[ClientComponentOnTheClient.filepath]['*'].id;
477478
delete webpackModules[clientId];
478479

479480
// Instead, we have to provide a translation from the client meta data to the SSR
480481
// meta data.
481-
const ssrMetaData = webpackMap[ClientComponentOnTheServer.filepath]['*'];
482+
const ssrMetaData =
483+
webpackMap.clientManifest[ClientComponentOnTheServer.filepath]['*'];
482484
const translationMap = {
483485
[clientId]: {
484486
'*': ssrMetaData,

packages/react-server-dom-webpack/src/__tests__/utils/WebpackMock.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Module = require('module');
1313
let webpackModuleIdx = 0;
1414
const webpackModules = {};
1515
const webpackErroredModules = {};
16-
const webpackMap = {};
16+
const webpackMap = {clientManifest: {}};
1717
global.__webpack_require__ = function (id) {
1818
if (webpackErroredModules[id]) {
1919
throw webpackErroredModules[id];
@@ -44,7 +44,7 @@ exports.clientModuleError = function clientModuleError(moduleError) {
4444
const idx = '' + webpackModuleIdx++;
4545
webpackErroredModules[idx] = moduleError;
4646
const path = url.pathToFileURL(idx).href;
47-
webpackMap[path] = {
47+
webpackMap.clientManifest[path] = {
4848
'': {
4949
id: idx,
5050
chunks: [],
@@ -65,7 +65,7 @@ exports.clientExports = function clientExports(moduleExports) {
6565
const idx = '' + webpackModuleIdx++;
6666
webpackModules[idx] = moduleExports;
6767
const path = url.pathToFileURL(idx).href;
68-
webpackMap[path] = {
68+
webpackMap.clientManifest[path] = {
6969
'': {
7070
id: idx,
7171
chunks: [],
@@ -81,7 +81,7 @@ exports.clientExports = function clientExports(moduleExports) {
8181
moduleExports.then(
8282
asyncModuleExports => {
8383
for (const name in asyncModuleExports) {
84-
webpackMap[path][name] = {
84+
webpackMap.clientManifest[path][name] = {
8585
id: idx,
8686
chunks: [],
8787
name: name,
@@ -92,7 +92,7 @@ exports.clientExports = function clientExports(moduleExports) {
9292
);
9393
}
9494
for (const name in moduleExports) {
95-
webpackMap[path][name] = {
95+
webpackMap.clientManifest[path][name] = {
9696
id: idx,
9797
chunks: [],
9898
name: name,

0 commit comments

Comments
 (0)