dillon1000/react
Commit
Browse files [Flight] Fallback to importing the whole module instead of encoding every name (#26624)
We currently don't just "require" a module by its module id/path. We encode the pair of module id/path AND its export name. That's because with module splitting, a single original module can end up in two or more separate modules by name. Therefore the manifest files need to encode how to require the whole module as well as how to require each export name. In practice, we don't currently use this because we end up forcing Webpack to deopt and keep it together as a single module, and we don't even have the code in the Webpack plugin to write separate values for each export name. The problem is with CJS we don't statically know what all the export names will be. Since these cases will never be module split, we don't really need to know. This changes the Flight requires to first look for the specific name we're loading and then if that name doesn't exist in the manifest we fallback to looking for the `"*"` name containing the entire module and look for the name in there at runtime. We could probably optimize this a bit if we assume that CJS modules on the server never get built with a name. That way we don't have to do the failed lookup. Additionally, since we've recently merged filepath + name into a single string instead of two values, we now have to split those back out by parsing the string. This is especially unfortunate for server references since those should really not reveal what they are but be a hash or something. The solution might just be to split them back out into two separate fields again. cc @shuding
Changed paths7 files
First-parent comparisonpackages/react-server-dom-webpack/src/ReactFlightClientConfigNodeBundler.js ModifiedM packages/react-server-dom-webpack/src/ReactFlightClientConfigWebpackBundler.js ModifiedM packages/react-server-dom-webpack/src/ReactFlightServerConfigWebpackBundler.js ModifiedM packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js ModifiedM packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js ModifiedM packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js ModifiedM packages/react-server-dom-webpack/src/__tests__/utils/WebpackMock.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…