Skip to content

Commit

Permalink
[Flight] Fix Webpack Chunk Loading (#25271)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sebmarkbage authored and rickhanlonii committed Oct 5, 2022
1 parent 608c495 commit a1ebbf4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions fixtures/flight/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import {Suspense} from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import ReactServerDOMReader from 'react-server-dom-webpack';

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

ReactDOM.render(
ReactDOM.createRoot(document.getElementById('root')).render(
<Suspense fallback={<h1>Loading...</h1>}>
<Content />
</Suspense>,
document.getElementById('root')
</Suspense>
);
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function resolveModuleReference<T>(
// If they're still pending they're a thenable. This map also exists
// in Webpack but unfortunately it's not exposed so we have to
// replicate it in user space. null means that it has already loaded.
const chunkCache: Map<string, null | Promise<any> | Error> = new Map();
const chunkCache: Map<string, null | Promise<any>> = new Map();
const asyncModuleCache: Map<string, Thenable<any>> = new Map();

// Start preloading the modules since we might need them soon.
Expand All @@ -72,9 +72,10 @@ export function preloadModule<T>(
const thenable = __webpack_chunk_load__(chunkId);
promises.push(thenable);
const resolve = chunkCache.set.bind(chunkCache, chunkId, null);
const reject = chunkCache.set.bind(chunkCache, chunkId);
thenable.then(resolve, reject);
thenable.then(resolve);
chunkCache.set(chunkId, thenable);
} else if (entry !== null) {
promises.push(entry);
}
}
if (moduleData.async) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import {acorn} from 'acorn';
import * as acorn from 'acorn';

type ResolveContext = {
conditions: Array<string>,
Expand Down

0 comments on commit a1ebbf4

Please sign in to comment.