From c5d06fdc5daf0605a035b283207f349abb990d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Wed, 14 Sep 2022 22:57:35 -0400 Subject: [PATCH] [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 --- fixtures/flight/src/index.js | 7 +++---- .../src/ReactFlightClientWebpackBundlerConfig.js | 7 ++++--- .../src/ReactFlightWebpackNodeLoader.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fixtures/flight/src/index.js b/fixtures/flight/src/index.js index b54a69ed7ba26..0c35d289c2be2 100644 --- a/fixtures/flight/src/index.js +++ b/fixtures/flight/src/index.js @@ -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( Loading...}> - , - document.getElementById('root') + ); diff --git a/packages/react-server-dom-webpack/src/ReactFlightClientWebpackBundlerConfig.js b/packages/react-server-dom-webpack/src/ReactFlightClientWebpackBundlerConfig.js index 5c47c7736d061..80f02f58b0efe 100644 --- a/packages/react-server-dom-webpack/src/ReactFlightClientWebpackBundlerConfig.js +++ b/packages/react-server-dom-webpack/src/ReactFlightClientWebpackBundlerConfig.js @@ -55,7 +55,7 @@ export function resolveModuleReference( // 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 | Error> = new Map(); +const chunkCache: Map> = new Map(); const asyncModuleCache: Map> = new Map(); // Start preloading the modules since we might need them soon. @@ -72,9 +72,10 @@ export function preloadModule( 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) { diff --git a/packages/react-server-dom-webpack/src/ReactFlightWebpackNodeLoader.js b/packages/react-server-dom-webpack/src/ReactFlightWebpackNodeLoader.js index 3182d1ab16cdf..16efd31d7f7c9 100644 --- a/packages/react-server-dom-webpack/src/ReactFlightWebpackNodeLoader.js +++ b/packages/react-server-dom-webpack/src/ReactFlightWebpackNodeLoader.js @@ -7,7 +7,7 @@ * @flow */ -import {acorn} from 'acorn'; +import * as acorn from 'acorn'; type ResolveContext = { conditions: Array,