Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flight] Fallback to importing the whole module instead of encoding every name #26624

Merged
merged 1 commit into from
Apr 15, 2023

Conversation

sebmarkbage
Copy link
Collaborator

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

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 14, 2023
@react-sizebot
Copy link

Comparing: 7b0642b...38b0ae6

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 164.35 kB 164.35 kB = 51.65 kB 51.65 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 166.79 kB 166.79 kB = 52.31 kB 52.31 kB
facebook-www/ReactDOM-prod.classic.js = 564.28 kB 564.28 kB = 99.34 kB 99.34 kB
facebook-www/ReactDOM-prod.modern.js = 548.07 kB 548.07 kB = 96.64 kB 96.64 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.04% 6.39 kB 6.65 kB +4.28% 2.55 kB 2.66 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.04% 6.39 kB 6.65 kB +4.28% 2.55 kB 2.66 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.04% 6.39 kB 6.65 kB +4.28% 2.55 kB 2.66 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +3.03% 18.97 kB 19.55 kB +2.86% 6.78 kB 6.98 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +3.03% 18.97 kB 19.55 kB +2.86% 6.78 kB 6.98 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +3.03% 18.97 kB 19.55 kB +2.86% 6.78 kB 6.98 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +2.99% 19.18 kB 19.76 kB +2.90% 6.89 kB 7.09 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +2.99% 19.18 kB 19.76 kB +2.90% 6.89 kB 7.09 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +2.99% 19.18 kB 19.76 kB +2.90% 6.89 kB 7.09 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +2.98% 19.26 kB 19.83 kB +2.85% 6.88 kB 7.07 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +2.98% 19.26 kB 19.83 kB +2.85% 6.88 kB 7.07 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +2.98% 19.26 kB 19.83 kB +2.85% 6.88 kB 7.07 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +2.85% 20.13 kB 20.71 kB +2.78% 7.17 kB 7.36 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +2.85% 20.13 kB 20.71 kB +2.78% 7.17 kB 7.36 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +2.85% 20.13 kB 20.71 kB +2.78% 7.17 kB 7.36 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +2.79% 6.83 kB 7.03 kB +3.09% 2.75 kB 2.84 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +2.79% 6.83 kB 7.03 kB +3.09% 2.75 kB 2.84 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +2.79% 6.83 kB 7.03 kB +3.09% 2.75 kB 2.84 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +2.77% 6.90 kB 7.09 kB +3.00% 2.80 kB 2.89 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +2.77% 6.90 kB 7.09 kB +3.00% 2.80 kB 2.89 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +2.77% 6.90 kB 7.09 kB +3.00% 2.80 kB 2.89 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.39% 23.72 kB 24.29 kB +2.62% 6.22 kB 6.38 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.39% 23.72 kB 24.29 kB +2.62% 6.22 kB 6.38 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.39% 23.72 kB 24.29 kB +2.62% 6.22 kB 6.38 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +2.20% 8.67 kB 8.86 kB +2.36% 3.44 kB 3.52 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +2.20% 8.67 kB 8.86 kB +2.36% 3.44 kB 3.52 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +2.20% 8.67 kB 8.86 kB +2.36% 3.44 kB 3.52 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +2.16% 8.91 kB 9.10 kB +2.29% 3.54 kB 3.62 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +2.16% 8.91 kB 9.10 kB +2.29% 3.54 kB 3.62 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +2.16% 8.91 kB 9.10 kB +2.29% 3.54 kB 3.62 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.05% 81.18 kB 82.84 kB +2.91% 19.68 kB 20.25 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.05% 81.18 kB 82.84 kB +2.91% 19.68 kB 20.25 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.05% 81.18 kB 82.84 kB +2.91% 19.68 kB 20.25 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.04% 81.67 kB 83.33 kB +2.85% 19.82 kB 20.39 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.04% 81.67 kB 83.33 kB +2.85% 19.82 kB 20.39 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.04% 81.67 kB 83.33 kB +2.85% 19.82 kB 20.39 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.03% 85.81 kB 87.55 kB +2.85% 19.95 kB 20.52 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.03% 85.81 kB 87.55 kB +2.85% 19.95 kB 20.52 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.03% 85.81 kB 87.55 kB +2.85% 19.95 kB 20.52 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.85 kB 4.62 kB = 2.10 kB 2.03 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.85 kB 4.62 kB = 2.10 kB 2.03 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.85 kB 4.62 kB = 2.10 kB 2.03 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.04% 6.39 kB 6.65 kB +4.28% 2.55 kB 2.66 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.04% 6.39 kB 6.65 kB +4.28% 2.55 kB 2.66 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.04% 6.39 kB 6.65 kB +4.28% 2.55 kB 2.66 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +3.03% 18.97 kB 19.55 kB +2.86% 6.78 kB 6.98 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +3.03% 18.97 kB 19.55 kB +2.86% 6.78 kB 6.98 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +3.03% 18.97 kB 19.55 kB +2.86% 6.78 kB 6.98 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +2.99% 19.18 kB 19.76 kB +2.90% 6.89 kB 7.09 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +2.99% 19.18 kB 19.76 kB +2.90% 6.89 kB 7.09 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +2.99% 19.18 kB 19.76 kB +2.90% 6.89 kB 7.09 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +2.98% 19.26 kB 19.83 kB +2.85% 6.88 kB 7.07 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +2.98% 19.26 kB 19.83 kB +2.85% 6.88 kB 7.07 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +2.98% 19.26 kB 19.83 kB +2.85% 6.88 kB 7.07 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +2.85% 20.13 kB 20.71 kB +2.78% 7.17 kB 7.36 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +2.85% 20.13 kB 20.71 kB +2.78% 7.17 kB 7.36 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +2.85% 20.13 kB 20.71 kB +2.78% 7.17 kB 7.36 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +2.79% 6.83 kB 7.03 kB +3.09% 2.75 kB 2.84 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +2.79% 6.83 kB 7.03 kB +3.09% 2.75 kB 2.84 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +2.79% 6.83 kB 7.03 kB +3.09% 2.75 kB 2.84 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +2.77% 6.90 kB 7.09 kB +3.00% 2.80 kB 2.89 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +2.77% 6.90 kB 7.09 kB +3.00% 2.80 kB 2.89 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +2.77% 6.90 kB 7.09 kB +3.00% 2.80 kB 2.89 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.39% 23.72 kB 24.29 kB +2.62% 6.22 kB 6.38 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.39% 23.72 kB 24.29 kB +2.62% 6.22 kB 6.38 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.39% 23.72 kB 24.29 kB +2.62% 6.22 kB 6.38 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +2.20% 8.67 kB 8.86 kB +2.36% 3.44 kB 3.52 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +2.20% 8.67 kB 8.86 kB +2.36% 3.44 kB 3.52 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +2.20% 8.67 kB 8.86 kB +2.36% 3.44 kB 3.52 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +2.16% 8.91 kB 9.10 kB +2.29% 3.54 kB 3.62 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +2.16% 8.91 kB 9.10 kB +2.29% 3.54 kB 3.62 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +2.16% 8.91 kB 9.10 kB +2.29% 3.54 kB 3.62 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.05% 81.18 kB 82.84 kB +2.91% 19.68 kB 20.25 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.05% 81.18 kB 82.84 kB +2.91% 19.68 kB 20.25 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.05% 81.18 kB 82.84 kB +2.91% 19.68 kB 20.25 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.04% 81.67 kB 83.33 kB +2.85% 19.82 kB 20.39 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.04% 81.67 kB 83.33 kB +2.85% 19.82 kB 20.39 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.04% 81.67 kB 83.33 kB +2.85% 19.82 kB 20.39 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.03% 85.81 kB 87.55 kB +2.85% 19.95 kB 20.52 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.03% 85.81 kB 87.55 kB +2.85% 19.95 kB 20.52 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.03% 85.81 kB 87.55 kB +2.85% 19.95 kB 20.52 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +1.98% 84.16 kB 85.83 kB +2.85% 20.19 kB 20.76 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +1.98% 84.16 kB 85.83 kB +2.85% 20.19 kB 20.76 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +1.98% 84.16 kB 85.83 kB +2.85% 20.19 kB 20.76 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +1.77% 25.38 kB 25.82 kB +2.22% 6.68 kB 6.82 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +1.77% 25.38 kB 25.82 kB +2.22% 6.68 kB 6.82 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +1.77% 25.38 kB 25.82 kB +2.22% 6.68 kB 6.82 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +1.76% 25.58 kB 26.03 kB +2.20% 6.76 kB 6.91 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +1.76% 25.58 kB 26.03 kB +2.20% 6.76 kB 6.91 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +1.76% 25.58 kB 26.03 kB +2.20% 6.76 kB 6.91 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.26% 19.89 kB 20.14 kB +1.51% 7.07 kB 7.18 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.26% 19.89 kB 20.14 kB +1.51% 7.07 kB 7.18 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.26% 19.89 kB 20.14 kB +1.51% 7.07 kB 7.18 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +1.03% 43.65 kB 44.10 kB +1.38% 10.77 kB 10.92 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +1.03% 43.65 kB 44.10 kB +1.38% 10.77 kB 10.92 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +1.03% 43.65 kB 44.10 kB +1.38% 10.77 kB 10.92 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +1.01% 46.41 kB 46.88 kB +1.36% 10.95 kB 11.10 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +1.01% 46.41 kB 46.88 kB +1.36% 10.95 kB 11.10 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +1.01% 46.41 kB 46.88 kB +1.36% 10.95 kB 11.10 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.90% 82.77 kB 83.52 kB +1.39% 19.81 kB 20.08 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.90% 82.77 kB 83.52 kB +1.39% 19.81 kB 20.08 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +0.90% 82.77 kB 83.52 kB +1.39% 19.81 kB 20.08 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.85 kB 4.62 kB = 2.10 kB 2.03 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.85 kB 4.62 kB = 2.10 kB 2.03 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.85 kB 4.62 kB = 2.10 kB 2.03 kB

Generated by 🚫 dangerJS against 38b0ae6

@sebmarkbage sebmarkbage merged commit da6c23a into facebook:main Apr 15, 2023
kassens pushed a commit to kassens/react that referenced this pull request Apr 17, 2023
…very name (facebook#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
kodiakhq bot pushed a commit to vercel/next.js that referenced this pull request Jun 13, 2023
Both of our bundlers won't split different exports of a module into different chunks, we can rely on facebook/react#26624 to simplify the structure. This reduces the size of the client reference manifest by ~70%.
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
…very name (facebook#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
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
…very 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

DiffTrain build for commit da6c23a.
sebmarkbage pushed a commit that referenced this pull request Sep 13, 2024
In #26624, the ability to mark a client reference module as `async` in
the React client manifest was removed because it was not utilized by
Webpack, neither in `ReactFlightWebpackPlugin` nor in Next.js. However,
some bundlers and frameworks are sophisticated enough to properly handle
and identify async ESM modules (e.g., client component modules with
top-level `await`), most notably Turbopack in Next.js. Therefore, we
need to consider the `async` flag in the client manifest when resolving
the client reference metadata on the server. The SSR manifest cannot
override this flag, meaning that if a module is async, it must remain
async in all client environments.

x-ref: vercel/next.js#70022
github-actions bot pushed a commit that referenced this pull request Sep 13, 2024
In #26624, the ability to mark a client reference module as `async` in
the React client manifest was removed because it was not utilized by
Webpack, neither in `ReactFlightWebpackPlugin` nor in Next.js. However,
some bundlers and frameworks are sophisticated enough to properly handle
and identify async ESM modules (e.g., client component modules with
top-level `await`), most notably Turbopack in Next.js. Therefore, we
need to consider the `async` flag in the client manifest when resolving
the client reference metadata on the server. The SSR manifest cannot
override this flag, meaning that if a module is async, it must remain
async in all client environments.

x-ref: vercel/next.js#70022

DiffTrain build for [5deb782](5deb782)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants