Skip to content

Commit a1ebbf4

Browse files
sebmarkbagerickhanlonii
authored andcommitted
[Flight] Fix Webpack Chunk Loading (#25271)
* Fix acorn import I'm not sure how this ever worked. * Fix cache to wait for entries already added to the chunk cache * Modernize API
1 parent 608c495 commit a1ebbf4

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

fixtures/flight/src/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import {Suspense} from 'react';
3-
import ReactDOM from 'react-dom';
3+
import ReactDOM from 'react-dom/client';
44
import ReactServerDOMReader from 'react-server-dom-webpack';
55

66
let data = ReactServerDOMReader.createFromFetch(fetch('http://localhost:3001'));
@@ -9,9 +9,8 @@ function Content() {
99
return React.experimental_use(data);
1010
}
1111

12-
ReactDOM.render(
12+
ReactDOM.createRoot(document.getElementById('root')).render(
1313
<Suspense fallback={<h1>Loading...</h1>}>
1414
<Content />
15-
</Suspense>,
16-
document.getElementById('root')
15+
</Suspense>
1716
);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function resolveModuleReference<T>(
5555
// If they're still pending they're a thenable. This map also exists
5656
// in Webpack but unfortunately it's not exposed so we have to
5757
// replicate it in user space. null means that it has already loaded.
58-
const chunkCache: Map<string, null | Promise<any> | Error> = new Map();
58+
const chunkCache: Map<string, null | Promise<any>> = new Map();
5959
const asyncModuleCache: Map<string, Thenable<any>> = new Map();
6060

6161
// Start preloading the modules since we might need them soon.
@@ -72,9 +72,10 @@ export function preloadModule<T>(
7272
const thenable = __webpack_chunk_load__(chunkId);
7373
promises.push(thenable);
7474
const resolve = chunkCache.set.bind(chunkCache, chunkId, null);
75-
const reject = chunkCache.set.bind(chunkCache, chunkId);
76-
thenable.then(resolve, reject);
75+
thenable.then(resolve);
7776
chunkCache.set(chunkId, thenable);
77+
} else if (entry !== null) {
78+
promises.push(entry);
7879
}
7980
}
8081
if (moduleData.async) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import {acorn} from 'acorn';
10+
import * as acorn from 'acorn';
1111

1212
type ResolveContext = {
1313
conditions: Array<string>,

0 commit comments

Comments
 (0)