Skip to content

Commit 5451e71

Browse files
committed
Special case plain CJS requires and conditional imports using __esModule
This models if the server tries to import .default or a plain require. We should replicate the same thing on the client when we load that module reference.
1 parent 0e002b9 commit 5451e71

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

fixtures/flight/server/handler.server.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ module.exports = async function(req, res) {
3636
chunks: ['3'],
3737
name: 'default',
3838
},
39+
'': {
40+
id: './src/ShowMore.client.js',
41+
chunks: ['3'],
42+
name: '',
43+
},
44+
'*': {
45+
id: './src/ShowMore.client.js',
46+
chunks: ['3'],
47+
name: '*',
48+
},
3949
},
4050
});
4151
};

packages/react-transport-dom-webpack/src/ReactFlightClientWebpackBundlerConfig.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,16 @@ export function requireModule<T>(moduleData: ModuleReference<T>): T {
5959
throw entry;
6060
}
6161
}
62-
return __webpack_require__(moduleData.id)[moduleData.name];
62+
const moduleExports = __webpack_require__(moduleData.id);
63+
if (moduleData.name === '*') {
64+
// This is a placeholder value that represents that the caller imported this
65+
// as a CommonJS module as is.
66+
return moduleExports;
67+
}
68+
if (moduleData.name === '') {
69+
// This is a placeholder value that represents that the caller accessed the
70+
// default property of this if it was an ESM interop module.
71+
return moduleExports.__esModule ? moduleExports.default : moduleExports;
72+
}
73+
return moduleExports[moduleData.name];
6374
}

scripts/flow/environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ declare module 'EventListener' {
6868
}
6969

7070
declare function __webpack_chunk_load__(id: string): Promise<mixed>;
71-
declare function __webpack_require__(id: string): {default: any};
71+
declare function __webpack_require__(id: string): any;

0 commit comments

Comments
 (0)