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] Add Support for Map and Set #26933

Merged
merged 3 commits into from
Jun 27, 2023

Conversation

sebmarkbage
Copy link
Collaborator

We already support these in the sense that they're Iterable so they just get serialized as arrays. However, these are part of the Structured Clone algorithm and should be supported.

The encoding is simply the same form as the Iterable, which is conveniently the same as the constructor argument. The difference is that now there's a separate reference to it.

It's a bit awkward because for multiple reference to the same value, it'd be a new Map/Set instance for each reference. So to encode sharing, it needs one level of indirection with its own ID. That's not really a big deal for other types since they're inline anyway - but since this needs to be outlined it creates possibly two ids where there only needs to be one or zero.

One variant would be to encode this in the row type. Another variant would be something like what we do for React Elements where they're arrays but tagged with a symbol. For simplicity I stick with the simple outlining for now.

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

react-sizebot commented Jun 13, 2023

Comparing: db50164...cf2cdec

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.23 kB 164.23 kB = 51.73 kB 51.72 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 171.67 kB 171.67 kB = 53.97 kB 53.97 kB
facebook-www/ReactDOM-prod.classic.js = 570.12 kB 570.12 kB = 100.58 kB 100.58 kB
facebook-www/ReactDOM-prod.modern.js = 553.90 kB 553.90 kB = 97.75 kB 97.75 kB
oss-experimental/react-client/cjs/react-client-flight.production.min.js +4.65% 8.76 kB 9.16 kB +1.53% 3.54 kB 3.59 kB
oss-stable-semver/react-client/cjs/react-client-flight.production.min.js +4.65% 8.76 kB 9.16 kB +1.53% 3.54 kB 3.59 kB
oss-stable/react-client/cjs/react-client-flight.production.min.js +4.65% 8.76 kB 9.16 kB +1.53% 3.54 kB 3.59 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.19% 9.70 kB 10.10 kB +1.44% 3.89 kB 3.95 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.19% 9.70 kB 10.10 kB +1.44% 3.89 kB 3.95 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.19% 9.70 kB 10.10 kB +1.44% 3.89 kB 3.95 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.min.js +4.06% 10.00 kB 10.40 kB +1.46% 3.96 kB 4.02 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.min.js +4.06% 10.00 kB 10.40 kB +1.46% 3.96 kB 4.02 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.min.js +4.06% 10.00 kB 10.40 kB +1.46% 3.96 kB 4.02 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.05% 10.02 kB 10.42 kB +1.39% 4.02 kB 4.08 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.05% 10.02 kB 10.42 kB +1.39% 4.02 kB 4.08 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.05% 10.02 kB 10.42 kB +1.39% 4.02 kB 4.08 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +3.90% 10.40 kB 10.80 kB +1.28% 4.21 kB 4.26 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +3.90% 10.40 kB 10.80 kB +1.28% 4.21 kB 4.26 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +3.90% 10.40 kB 10.80 kB +1.28% 4.21 kB 4.26 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +3.81% 10.65 kB 11.06 kB +1.35% 4.28 kB 4.34 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +3.81% 10.65 kB 11.06 kB +1.35% 4.28 kB 4.34 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +3.81% 10.65 kB 11.06 kB +1.35% 4.28 kB 4.34 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +3.80% 10.67 kB 11.08 kB +1.15% 4.26 kB 4.31 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +3.80% 10.67 kB 11.08 kB +1.15% 4.26 kB 4.31 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +3.80% 10.67 kB 11.08 kB +1.15% 4.26 kB 4.31 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +3.72% 10.94 kB 11.34 kB +1.26% 4.36 kB 4.41 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +3.72% 10.94 kB 11.34 kB +1.26% 4.36 kB 4.41 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +3.72% 10.94 kB 11.34 kB +1.26% 4.36 kB 4.41 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.min.js +2.99% 38.53 kB 39.68 kB +1.44% 9.70 kB 9.84 kB
oss-stable-semver/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.min.js +2.99% 38.53 kB 39.68 kB +1.44% 9.70 kB 9.84 kB
oss-stable/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.min.js +2.99% 38.53 kB 39.68 kB +1.44% 9.70 kB 9.84 kB
oss-experimental/react-client/cjs/react-client-flight.development.js +2.42% 47.02 kB 48.15 kB +1.24% 11.87 kB 12.02 kB
oss-stable-semver/react-client/cjs/react-client-flight.development.js +2.42% 47.02 kB 48.15 kB +1.24% 11.87 kB 12.02 kB
oss-stable/react-client/cjs/react-client-flight.development.js +2.42% 47.02 kB 48.15 kB +1.24% 11.87 kB 12.02 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.29% 49.69 kB 50.83 kB +1.17% 12.34 kB 12.49 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.29% 49.69 kB 50.83 kB +1.17% 12.34 kB 12.49 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.29% 49.69 kB 50.83 kB +1.17% 12.34 kB 12.49 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.25% 50.59 kB 51.73 kB +1.14% 12.56 kB 12.70 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.25% 50.59 kB 51.73 kB +1.14% 12.56 kB 12.70 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.25% 50.59 kB 51.73 kB +1.14% 12.56 kB 12.70 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.25% 50.64 kB 51.78 kB +1.13% 12.45 kB 12.59 kB
oss-stable-semver/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.25% 50.64 kB 51.78 kB +1.13% 12.45 kB 12.59 kB
oss-stable/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.25% 50.64 kB 51.78 kB +1.13% 12.45 kB 12.59 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.24% 50.80 kB 51.94 kB +1.13% 12.50 kB 12.65 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.24% 50.80 kB 51.94 kB +1.13% 12.50 kB 12.65 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.24% 50.80 kB 51.94 kB +1.13% 12.50 kB 12.65 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.19% 52.13 kB 53.26 kB +1.09% 13.01 kB 13.15 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.19% 52.13 kB 53.26 kB +1.09% 13.01 kB 13.15 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.19% 52.13 kB 53.26 kB +1.09% 13.01 kB 13.15 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.16% 56.59 kB 57.81 kB +1.07% 13.39 kB 13.53 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.16% 56.59 kB 57.81 kB +1.07% 13.39 kB 13.53 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.16% 56.59 kB 57.81 kB +1.07% 13.39 kB 13.53 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.16% 52.85 kB 53.99 kB +1.10% 13.16 kB 13.31 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.16% 52.85 kB 53.99 kB +1.10% 13.16 kB 13.31 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.16% 52.85 kB 53.99 kB +1.10% 13.16 kB 13.31 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.14% 53.21 kB 54.35 kB +1.06% 13.18 kB 13.32 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.14% 53.21 kB 54.35 kB +1.06% 13.18 kB 13.32 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.14% 53.21 kB 54.35 kB +1.06% 13.18 kB 13.32 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-client/cjs/react-client-flight.production.min.js +4.65% 8.76 kB 9.16 kB +1.53% 3.54 kB 3.59 kB
oss-stable-semver/react-client/cjs/react-client-flight.production.min.js +4.65% 8.76 kB 9.16 kB +1.53% 3.54 kB 3.59 kB
oss-stable/react-client/cjs/react-client-flight.production.min.js +4.65% 8.76 kB 9.16 kB +1.53% 3.54 kB 3.59 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.19% 9.70 kB 10.10 kB +1.44% 3.89 kB 3.95 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.19% 9.70 kB 10.10 kB +1.44% 3.89 kB 3.95 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.min.js +4.19% 9.70 kB 10.10 kB +1.44% 3.89 kB 3.95 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.min.js +4.06% 10.00 kB 10.40 kB +1.46% 3.96 kB 4.02 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.min.js +4.06% 10.00 kB 10.40 kB +1.46% 3.96 kB 4.02 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.min.js +4.06% 10.00 kB 10.40 kB +1.46% 3.96 kB 4.02 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.05% 10.02 kB 10.42 kB +1.39% 4.02 kB 4.08 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.05% 10.02 kB 10.42 kB +1.39% 4.02 kB 4.08 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +4.05% 10.02 kB 10.42 kB +1.39% 4.02 kB 4.08 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +3.90% 10.40 kB 10.80 kB +1.28% 4.21 kB 4.26 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +3.90% 10.40 kB 10.80 kB +1.28% 4.21 kB 4.26 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js +3.90% 10.40 kB 10.80 kB +1.28% 4.21 kB 4.26 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +3.81% 10.65 kB 11.06 kB +1.35% 4.28 kB 4.34 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +3.81% 10.65 kB 11.06 kB +1.35% 4.28 kB 4.34 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js +3.81% 10.65 kB 11.06 kB +1.35% 4.28 kB 4.34 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +3.80% 10.67 kB 11.08 kB +1.15% 4.26 kB 4.31 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +3.80% 10.67 kB 11.08 kB +1.15% 4.26 kB 4.31 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js +3.80% 10.67 kB 11.08 kB +1.15% 4.26 kB 4.31 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +3.72% 10.94 kB 11.34 kB +1.26% 4.36 kB 4.41 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +3.72% 10.94 kB 11.34 kB +1.26% 4.36 kB 4.41 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js +3.72% 10.94 kB 11.34 kB +1.26% 4.36 kB 4.41 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.min.js +2.99% 38.53 kB 39.68 kB +1.44% 9.70 kB 9.84 kB
oss-stable-semver/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.min.js +2.99% 38.53 kB 39.68 kB +1.44% 9.70 kB 9.84 kB
oss-stable/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.min.js +2.99% 38.53 kB 39.68 kB +1.44% 9.70 kB 9.84 kB
oss-experimental/react-client/cjs/react-client-flight.development.js +2.42% 47.02 kB 48.15 kB +1.24% 11.87 kB 12.02 kB
oss-stable-semver/react-client/cjs/react-client-flight.development.js +2.42% 47.02 kB 48.15 kB +1.24% 11.87 kB 12.02 kB
oss-stable/react-client/cjs/react-client-flight.development.js +2.42% 47.02 kB 48.15 kB +1.24% 11.87 kB 12.02 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.29% 49.69 kB 50.83 kB +1.17% 12.34 kB 12.49 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.29% 49.69 kB 50.83 kB +1.17% 12.34 kB 12.49 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.29% 49.69 kB 50.83 kB +1.17% 12.34 kB 12.49 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.25% 50.59 kB 51.73 kB +1.14% 12.56 kB 12.70 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.25% 50.59 kB 51.73 kB +1.14% 12.56 kB 12.70 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.25% 50.59 kB 51.73 kB +1.14% 12.56 kB 12.70 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.25% 50.64 kB 51.78 kB +1.13% 12.45 kB 12.59 kB
oss-stable-semver/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.25% 50.64 kB 51.78 kB +1.13% 12.45 kB 12.59 kB
oss-stable/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.25% 50.64 kB 51.78 kB +1.13% 12.45 kB 12.59 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.24% 50.80 kB 51.94 kB +1.13% 12.50 kB 12.65 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.24% 50.80 kB 51.94 kB +1.13% 12.50 kB 12.65 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.24% 50.80 kB 51.94 kB +1.13% 12.50 kB 12.65 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.19% 52.13 kB 53.26 kB +1.09% 13.01 kB 13.15 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.19% 52.13 kB 53.26 kB +1.09% 13.01 kB 13.15 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.19% 52.13 kB 53.26 kB +1.09% 13.01 kB 13.15 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.16% 56.59 kB 57.81 kB +1.07% 13.39 kB 13.53 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.16% 56.59 kB 57.81 kB +1.07% 13.39 kB 13.53 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.16% 56.59 kB 57.81 kB +1.07% 13.39 kB 13.53 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.16% 52.85 kB 53.99 kB +1.10% 13.16 kB 13.31 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.16% 52.85 kB 53.99 kB +1.10% 13.16 kB 13.31 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.16% 52.85 kB 53.99 kB +1.10% 13.16 kB 13.31 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.14% 53.21 kB 54.35 kB +1.06% 13.18 kB 13.32 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.14% 53.21 kB 54.35 kB +1.06% 13.18 kB 13.32 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.14% 53.21 kB 54.35 kB +1.06% 13.18 kB 13.32 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +1.41% 21.94 kB 22.25 kB +0.85% 7.77 kB 7.84 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +1.41% 21.94 kB 22.25 kB +0.85% 7.77 kB 7.84 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +1.41% 21.94 kB 22.25 kB +0.85% 7.77 kB 7.84 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +1.39% 22.15 kB 22.46 kB +0.95% 7.87 kB 7.95 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +1.39% 22.15 kB 22.46 kB +0.95% 7.87 kB 7.95 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +1.39% 22.15 kB 22.46 kB +0.95% 7.87 kB 7.95 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +1.39% 22.25 kB 22.56 kB +0.83% 7.87 kB 7.94 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +1.39% 22.25 kB 22.56 kB +0.83% 7.87 kB 7.94 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.min.js +1.39% 22.25 kB 22.56 kB +0.83% 7.87 kB 7.94 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.min.js +1.34% 23.06 kB 23.37 kB +0.69% 8.10 kB 8.15 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.min.js +1.34% 23.06 kB 23.37 kB +0.69% 8.10 kB 8.15 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.min.js +1.34% 23.06 kB 23.37 kB +0.69% 8.10 kB 8.15 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.34% 23.17 kB 23.48 kB +0.76% 8.17 kB 8.23 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.34% 23.17 kB 23.48 kB +0.76% 8.17 kB 8.23 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +1.34% 23.17 kB 23.48 kB +0.76% 8.17 kB 8.23 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +1.31% 23.73 kB 24.04 kB +0.72% 8.36 kB 8.42 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +1.31% 23.73 kB 24.04 kB +0.72% 8.36 kB 8.42 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +1.31% 23.73 kB 24.04 kB +0.72% 8.36 kB 8.42 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +1.06% 96.51 kB 97.53 kB +0.89% 22.43 kB 22.63 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +1.06% 96.51 kB 97.53 kB +0.89% 22.43 kB 22.63 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +1.06% 96.51 kB 97.53 kB +0.89% 22.43 kB 22.63 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +1.04% 91.27 kB 92.22 kB +0.76% 22.10 kB 22.26 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +1.04% 91.27 kB 92.22 kB +0.76% 22.10 kB 22.26 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +1.04% 91.27 kB 92.22 kB +0.76% 22.10 kB 22.26 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +1.04% 91.68 kB 92.63 kB +0.75% 22.21 kB 22.37 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +1.04% 91.68 kB 92.63 kB +0.75% 22.21 kB 22.37 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +1.04% 91.68 kB 92.63 kB +0.75% 22.21 kB 22.37 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +1.02% 93.75 kB 94.70 kB +0.75% 22.39 kB 22.55 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +1.02% 93.75 kB 94.70 kB +0.75% 22.39 kB 22.55 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +1.02% 93.75 kB 94.70 kB +0.75% 22.39 kB 22.55 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1.01% 94.65 kB 95.61 kB +0.76% 22.62 kB 22.79 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1.01% 94.65 kB 95.61 kB +0.76% 22.62 kB 22.79 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1.01% 94.65 kB 95.61 kB +0.76% 22.62 kB 22.79 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.98% 96.97 kB 97.92 kB +0.75% 23.27 kB 23.44 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.98% 96.97 kB 97.92 kB +0.75% 23.27 kB 23.44 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.98% 96.97 kB 97.92 kB +0.75% 23.27 kB 23.44 kB
oss-experimental/react-server/cjs/react-server-flight.production.min.js +0.94% 16.20 kB 16.35 kB +0.65% 5.84 kB 5.88 kB
oss-stable-semver/react-server/cjs/react-server-flight.production.min.js +0.94% 16.20 kB 16.35 kB +0.65% 5.84 kB 5.88 kB
oss-stable/react-server/cjs/react-server-flight.production.min.js +0.94% 16.20 kB 16.35 kB +0.65% 5.84 kB 5.88 kB
oss-experimental/react-server/cjs/react-server-flight.development.js +0.82% 66.51 kB 67.06 kB +0.66% 16.03 kB 16.13 kB
oss-stable-semver/react-server/cjs/react-server-flight.development.js +0.82% 66.51 kB 67.06 kB +0.66% 16.03 kB 16.13 kB
oss-stable/react-server/cjs/react-server-flight.development.js +0.82% 66.51 kB 67.06 kB +0.66% 16.03 kB 16.13 kB

Generated by 🚫 dangerJS against cf2cdec

Copy link
Collaborator

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to encode sharing

How are shared values produced (something like <Component foo={map} bar={map} /> maybe)? Is this something we can test?

@@ -229,6 +241,24 @@ export function processReply(
});
return serializeFormDataReference(refId);
}
if (value instanceof Map) {
const partJSON = JSON.stringify(Array.from(value), resolveToJSON);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What's the purpose of the Array.from call here? I thought we already can stringify iterables so this seems redundant. Tests are passing without it. We Array.from it later anyway after we extracted the iterator so we might as well do it here since we know the value is iterable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also to avoid this being an infinite loop, since otherwise we'd just end up back here since Map is preferred over the Iterable path.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my local testing, dropping it here was fine, but not on Server. Or vice versa, I don't quite remember. Either way, the way you proposed makes it easier to follow.

@sebmarkbage
Copy link
Collaborator Author

How are shared values produced (something like maybe)?

We don't atm. Gets especially interesting for Map/Set objects since the object keys might not share references in this first PR. Technically we can't really guarantee referential identity across reloads/refreshes if they're not part of the same payload but that might be an edge case. That might be an argument against adding these until we have stronger guarantees about where referential identity is guaranteed.

The underlying issue is that a Server Component can show up anywhere and it can read Server Context anywhere so the same object might actually end up having two different values.

function ServerComponent() {
  return use(ServerContext);
}

let obj = { value: <ServerComponent /> };
<ServerContext.Provider value="a">
  <ClientComponent obj={obj} />
</ServerContext.Provider>
<ServerContext.Provider value="b">
  <ClientComponent obj={obj} />
</ServerContext.Provider>

This obj would have to have two different instances to represent the two different values. There's an idea to solve for this when possible, but it might not have strong guarantees when something suspends and is fairly complicated.

Copy link
Collaborator

@gnoff gnoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving because it seems to do what you intend it to but not sure we should do this until we have our answer for shared references.

I suppose we already don't support referential identity for arrays so at least the behavior here is consistent. We also don't support cycles here but that is already true for arrays as well. I can see the view that we have a problem and we shouldn't make it worse but similarly it's convincing that this problem already exists and a solution for arrays will be a solution for Map/Set so we can safely add this without complicating our predicament. How's that for "helpful" commentary

@sebmarkbage
Copy link
Collaborator Author

sebmarkbage commented Jun 27, 2023

I'll land this as is but I think the right place it probably to encode this in the row and not the reference after all even though it's more code I suspect it'll eventually be better since it's the right model to encode the referential identity of the map itself with the id. I learned this after implementing streams.

@sebmarkbage sebmarkbage merged commit a1c62b8 into facebook:main Jun 27, 2023
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
We already support these in the sense that they're Iterable so they just
get serialized as arrays. However, these are part of the Structured
Clone algorithm [and should be
supported](facebook#25687).

The encoding is simply the same form as the Iterable, which is
conveniently the same as the constructor argument. The difference is
that now there's a separate reference to it.

It's a bit awkward because for multiple reference to the same value,
it'd be a new Map/Set instance for each reference. So to encode sharing,
it needs one level of indirection with its own ID. That's not really a
big deal for other types since they're inline anyway - but since this
needs to be outlined it creates possibly two ids where there only needs
to be one or zero.

One variant would be to encode this in the row type. Another variant
would be something like what we do for React Elements where they're
arrays but tagged with a symbol. For simplicity I stick with the simple
outlining for now.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
We already support these in the sense that they're Iterable so they just
get serialized as arrays. However, these are part of the Structured
Clone algorithm [and should be
supported](#25687).

The encoding is simply the same form as the Iterable, which is
conveniently the same as the constructor argument. The difference is
that now there's a separate reference to it.

It's a bit awkward because for multiple reference to the same value,
it'd be a new Map/Set instance for each reference. So to encode sharing,
it needs one level of indirection with its own ID. That's not really a
big deal for other types since they're inline anyway - but since this
needs to be outlined it creates possibly two ids where there only needs
to be one or zero.

One variant would be to encode this in the row type. Another variant
would be something like what we do for React Elements where they're
arrays but tagged with a symbol. For simplicity I stick with the simple
outlining for now.

DiffTrain build for commit a1c62b8.
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.

5 participants