[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
This commit is contained in:
Sebastian Markbåge 2022-09-14 22:57:35 -04:00 committed by GitHub
parent 975b644643
commit c5d06fdc5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -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'));
@ -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>
);

View File

@ -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.
@ -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) {

View File

@ -7,7 +7,7 @@
* @flow
*/
import {acorn} from 'acorn';
import * as acorn from 'acorn';
type ResolveContext = {
conditions: Array<string>,