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] Transfer Debug Info in Server-to-Server Flight Requests #28275

Merged
merged 2 commits into from
Feb 12, 2024

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Feb 8, 2024

A Flight Server can be a consumer of a stream from another Server. In this case the meta data is attached to debugInfo properties on lazy, Promises, Arrays or Elements that might in turn get forwarded to the next stream. In this case we want to forward this debug information to the client in the stream.

I also added a DEV only environmentName option to the Flight Server. This lets you name the server that is producing the debug info so that you can trace the origin of where that component is executing. This defaults to "server". DevTools could use this for badges or different colors.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 8, 2024
@react-sizebot
Copy link

react-sizebot commented Feb 8, 2024

Comparing: d3def47...c4c5e0f

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 = 176.64 kB 176.64 kB = 55.02 kB 55.02 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 178.63 kB 178.63 kB = 55.59 kB 55.59 kB
facebook-www/ReactDOM-prod.classic.js = 591.73 kB 591.73 kB = 104.44 kB 104.44 kB
facebook-www/ReactDOM-prod.modern.js = 575.51 kB 575.51 kB = 101.53 kB 101.53 kB
oss-stable-semver/react-server/cjs/react-server-flight.development.js +4.27% 66.51 kB 69.35 kB +2.43% 16.20 kB 16.59 kB
oss-stable/react-server/cjs/react-server-flight.development.js +4.27% 66.51 kB 69.35 kB +2.43% 16.20 kB 16.59 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +4.05% 2.20 kB 2.28 kB +1.93% 0.88 kB 0.90 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +4.05% 2.20 kB 2.28 kB +1.93% 0.88 kB 0.90 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +4.05% 2.20 kB 2.28 kB +1.93% 0.88 kB 0.90 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js +3.74% 1.34 kB 1.39 kB +3.54% 0.62 kB 0.64 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js +3.74% 1.34 kB 1.39 kB +3.54% 0.62 kB 0.64 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js +3.74% 1.34 kB 1.39 kB +3.54% 0.62 kB 0.64 kB
oss-experimental/react-server/cjs/react-server-flight.development.js +3.73% 76.21 kB 79.05 kB +2.12% 18.18 kB 18.56 kB
facebook-www/ReactFlightDOMServer-dev.modern.js +3.68% 84.42 kB 87.53 kB +2.10% 18.25 kB 18.63 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +3.66% 2.43 kB 2.52 kB +1.82% 0.94 kB 0.95 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +3.66% 2.43 kB 2.52 kB +1.82% 0.94 kB 0.95 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +3.66% 2.43 kB 2.52 kB +1.82% 0.94 kB 0.95 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +2.87% 100.68 kB 103.57 kB +1.69% 23.99 kB 24.40 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +2.87% 100.68 kB 103.57 kB +1.69% 23.99 kB 24.40 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js +2.80% 102.95 kB 105.84 kB +1.62% 24.83 kB 25.23 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js +2.80% 102.95 kB 105.84 kB +1.62% 24.83 kB 25.23 kB
oss-stable-semver/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js +2.79% 108.73 kB 111.76 kB +1.73% 25.12 kB 25.55 kB
oss-stable/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js +2.79% 108.73 kB 111.76 kB +1.73% 25.12 kB 25.55 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js +2.79% 103.66 kB 106.54 kB +1.60% 25.02 kB 25.42 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js +2.79% 103.66 kB 106.54 kB +1.60% 25.02 kB 25.42 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.74% 105.54 kB 108.42 kB +1.59% 25.55 kB 25.95 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.74% 105.54 kB 108.42 kB +1.59% 25.55 kB 25.95 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.73% 105.72 kB 108.61 kB +1.56% 25.58 kB 25.98 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.73% 105.72 kB 108.61 kB +1.56% 25.58 kB 25.98 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js +2.72% 106.09 kB 108.98 kB +1.60% 25.20 kB 25.60 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js +2.72% 106.09 kB 108.98 kB +1.60% 25.20 kB 25.60 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.72% 111.45 kB 114.48 kB +1.61% 25.86 kB 26.27 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.72% 111.45 kB 114.48 kB +1.61% 25.86 kB 26.27 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2.66% 108.52 kB 111.40 kB +1.57% 25.81 kB 26.22 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2.66% 108.52 kB 111.40 kB +1.57% 25.81 kB 26.22 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js +2.66% 108.73 kB 111.62 kB +1.56% 26.03 kB 26.43 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js +2.66% 108.73 kB 111.62 kB +1.56% 26.03 kB 26.43 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +2.61% 111.26 kB 114.16 kB +1.53% 26.28 kB 26.68 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +2.60% 111.15 kB 114.04 kB +1.56% 26.68 kB 27.10 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +2.60% 111.15 kB 114.04 kB +1.56% 26.68 kB 27.10 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js +2.55% 113.33 kB 116.22 kB +1.49% 27.06 kB 27.47 kB
oss-experimental/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js +2.53% 119.56 kB 122.59 kB +1.38% 27.42 kB 27.80 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js +2.53% 114.71 kB 117.61 kB +1.50% 27.49 kB 27.90 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.49% 115.91 kB 118.80 kB +1.45% 27.79 kB 28.19 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js +2.48% 116.67 kB 119.57 kB +1.47% 27.49 kB 27.89 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.48% 116.77 kB 119.67 kB +1.47% 28.05 kB 28.46 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.48% 122.29 kB 125.31 kB +1.33% 28.14 kB 28.51 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2.43% 119.09 kB 121.99 kB +1.44% 28.11 kB 28.52 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js +2.43% 119.31 kB 122.21 kB +1.45% 28.32 kB 28.73 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +2.38% 121.73 kB 124.63 kB +1.43% 28.99 kB 29.41 kB
test_utils/ReactAllWarnings.js Deleted 67.02 kB 0.00 kB Deleted 16.42 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-server/cjs/react-server-flight.development.js +4.27% 66.51 kB 69.35 kB +2.43% 16.20 kB 16.59 kB
oss-stable/react-server/cjs/react-server-flight.development.js +4.27% 66.51 kB 69.35 kB +2.43% 16.20 kB 16.59 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +4.05% 2.20 kB 2.28 kB +1.93% 0.88 kB 0.90 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +4.05% 2.20 kB 2.28 kB +1.93% 0.88 kB 0.90 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.js +4.05% 2.20 kB 2.28 kB +1.93% 0.88 kB 0.90 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js +3.74% 1.34 kB 1.39 kB +3.54% 0.62 kB 0.64 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js +3.74% 1.34 kB 1.39 kB +3.54% 0.62 kB 0.64 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.production.min.js +3.74% 1.34 kB 1.39 kB +3.54% 0.62 kB 0.64 kB
oss-experimental/react-server/cjs/react-server-flight.development.js +3.73% 76.21 kB 79.05 kB +2.12% 18.18 kB 18.56 kB
facebook-www/ReactFlightDOMServer-dev.modern.js +3.68% 84.42 kB 87.53 kB +2.10% 18.25 kB 18.63 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +3.66% 2.43 kB 2.52 kB +1.82% 0.94 kB 0.95 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +3.66% 2.43 kB 2.52 kB +1.82% 0.94 kB 0.95 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-server.development.js +3.66% 2.43 kB 2.52 kB +1.82% 0.94 kB 0.95 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +2.87% 100.68 kB 103.57 kB +1.69% 23.99 kB 24.40 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +2.87% 100.68 kB 103.57 kB +1.69% 23.99 kB 24.40 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js +2.80% 102.95 kB 105.84 kB +1.62% 24.83 kB 25.23 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js +2.80% 102.95 kB 105.84 kB +1.62% 24.83 kB 25.23 kB
oss-stable-semver/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js +2.79% 108.73 kB 111.76 kB +1.73% 25.12 kB 25.55 kB
oss-stable/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js +2.79% 108.73 kB 111.76 kB +1.73% 25.12 kB 25.55 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js +2.79% 103.66 kB 106.54 kB +1.60% 25.02 kB 25.42 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js +2.79% 103.66 kB 106.54 kB +1.60% 25.02 kB 25.42 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.74% 105.54 kB 108.42 kB +1.59% 25.55 kB 25.95 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.74% 105.54 kB 108.42 kB +1.59% 25.55 kB 25.95 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.73% 105.72 kB 108.61 kB +1.56% 25.58 kB 25.98 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.73% 105.72 kB 108.61 kB +1.56% 25.58 kB 25.98 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js +2.72% 106.09 kB 108.98 kB +1.60% 25.20 kB 25.60 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js +2.72% 106.09 kB 108.98 kB +1.60% 25.20 kB 25.60 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.72% 111.45 kB 114.48 kB +1.61% 25.86 kB 26.27 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.72% 111.45 kB 114.48 kB +1.61% 25.86 kB 26.27 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2.66% 108.52 kB 111.40 kB +1.57% 25.81 kB 26.22 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2.66% 108.52 kB 111.40 kB +1.57% 25.81 kB 26.22 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js +2.66% 108.73 kB 111.62 kB +1.56% 26.03 kB 26.43 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js +2.66% 108.73 kB 111.62 kB +1.56% 26.03 kB 26.43 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +2.61% 111.26 kB 114.16 kB +1.53% 26.28 kB 26.68 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +2.60% 111.15 kB 114.04 kB +1.56% 26.68 kB 27.10 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +2.60% 111.15 kB 114.04 kB +1.56% 26.68 kB 27.10 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js +2.55% 113.33 kB 116.22 kB +1.49% 27.06 kB 27.47 kB
oss-experimental/react-server-dom-turbopack/umd/react-server-dom-turbopack-server.browser.development.js +2.53% 119.56 kB 122.59 kB +1.38% 27.42 kB 27.80 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js +2.53% 114.71 kB 117.61 kB +1.50% 27.49 kB 27.90 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +2.49% 115.91 kB 118.80 kB +1.45% 27.79 kB 28.19 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js +2.48% 116.67 kB 119.57 kB +1.47% 27.49 kB 27.89 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js +2.48% 116.77 kB 119.67 kB +1.47% 28.05 kB 28.46 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +2.48% 122.29 kB 125.31 kB +1.33% 28.14 kB 28.51 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2.43% 119.09 kB 121.99 kB +1.44% 28.11 kB 28.52 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js +2.43% 119.31 kB 122.21 kB +1.45% 28.32 kB 28.73 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +2.38% 121.73 kB 124.63 kB +1.43% 28.99 kB 29.41 kB
oss-stable-semver/react-server/cjs/react-server-flight.production.js +0.32% 56.77 kB 56.95 kB +0.44% 13.89 kB 13.95 kB
oss-stable/react-server/cjs/react-server-flight.production.js +0.32% 56.77 kB 56.95 kB +0.44% 13.89 kB 13.95 kB
oss-experimental/react-server/cjs/react-server-flight.production.js +0.27% 66.44 kB 66.62 kB +0.23% 15.88 kB 15.92 kB
test_utils/ReactAllWarnings.js Deleted 67.02 kB 0.00 kB Deleted 16.42 kB 0.00 kB

Generated by 🚫 dangerJS against c4c5e0f

@sebmarkbage sebmarkbage force-pushed the servertoserver branch 2 times, most recently from b5c0e57 to 053e9c1 Compare February 8, 2024 01:39
A Flight Server can be a consumer of a stream from another Server.

In this case the meta data is attached to debugInfo properties on lazy,
Promises, Arrays or Elements that might in turn get forwarded to the next
stream. In this case we want to forward this debug information to the
client.
This lets you name the server that is producing the debug info so that
you can trace the origin of where that component is executing.

function ServerComponent({transport}) {
// This is a Server Component that receives other Server Components from a third party.
const children = ReactNoopFlightClient.read(transport);
Copy link
Contributor

@unstubbable unstubbable Feb 8, 2024

Choose a reason for hiding this comment

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

This is an interesting case. Up until this PR I wasn't aware that server-to-server RSC is supposed to be supported. Unfortunately, this is not exposed as public API, or is it? I guess, we would need something like ReactFlightDOMClient.createFromFetch that works without an SSR manifest, and preserves client references, instead of trying to resolve them? Is this something that's planned?

Copy link
Contributor

Choose a reason for hiding this comment

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

(for context, the usecase is federation via RSC, as in https://x.com/dan_abramov2/status/1747983201748861274 for example. currently it requires... some stream serialization acrobatics)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Like anything else it's more of a bundler feature. You just need some way from the third party server to refer to "client" as meaning files in the "server". Like anything else the server needs a manifest from the client.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Btw, untrusted is NOT supported. Flight parsing isn't vetted from a security perspective if the protocol is from an untrusted source.

Copy link
Contributor

@lubieowoce lubieowoce Feb 8, 2024

Choose a reason for hiding this comment

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

hm. i'm not sure if a server being able to refer to things from another server is a prerequisite for this
(edit: it is, but WMF already has ways of doing this)

i think what @unstubbable was talking about is something that'd allow incorporating foreign (but trusted) trees server-side, without going into client-land. those trees wouldn't necessarily need to refer to things from the consuming server (and if they would, this'd likely be handled using "remotes", i.e. module federation's existing pattern for this).

so it's really more of an implementation headache. because right now this seems to require tunneling one RSC stream over another and then deserializing in client-land, as seen here:
https://twitter.com/lubieowoce/status/1744854538060771614?t=IK4O45iZvCU4isBmTHIf1A
and here:
https://twitter.com/ebey_jacob/status/1744793367085727952?t=fOPDaYf3LLelv7gYhvSuzQ&s=19
which works but seems unnecessarily cumbersome. granted, some of the cumbersomeness is just because Flight doesn't currently handle ReadableStreams as props, but even if it did, we'd still be tunneling

basically, i think the feature request would be for a server-land createFromReadableStream that keeps client references as references, so that it can be returned from a server component like any other element. (it's unfortunate that it'd have to parse just to serialize it right back, but i'm not sure if that can be avoided -- at the very least, rows need renumbering).

also if i'm missing something, @jacob-ebey can probably explain the use-case better, he's had experience implementing this, i just helped out with a couple bits.

ofc the federated use-case ALSO needs bundler support, because eventually you need to resolve those foreign client references to something. but i believe that's been implemented in userspace already, really """just""" a matter of hooking the existing machinery of module federation into it all.

(sorry for making this a huge long thing in a drive-by comment 😅 probably not the best place, hope you don't mind!)

Copy link
Collaborator Author

@sebmarkbage sebmarkbage Feb 9, 2024

Choose a reason for hiding this comment

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

Yea, I mean we'll support ReadableStream pass through but that's not really recommended. That's just module federation.

It needs to be deserialized and re-serialized so that the third-party can also render server components inside the first party and everything else can kick in. Sure, there's a slight perf hit but so does SSR. There could be optimizations added on top of that which can keep some parts pass through but that's an optimization and not the core model.

Copy link
Collaborator Author

@sebmarkbage sebmarkbage Feb 9, 2024

Choose a reason for hiding this comment

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

basically, i think the feature request would be for a server-land createFromReadableStream that keeps client references as references, so that it can be returned from a server component like any other element. (it's unfortunate that it'd have to parse just to serialize it right back, but i'm not sure if that can be avoided

Although now I'm confused what you mean because this is supported. That's what this PR uses.

There's no limitation that /client can't be used in react-server environments.

https://github.com/facebook/react/blob/main/packages/react-server-dom-webpack/package.json#L46-L49

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh I think I understand the misunderstanding. The confusion is that Client References isn't actually 1:1 with "use client". It's not supposed to preserve the Client References. Instead, the Client Reference of a Third Party is a reference to a module in the first party. Requiring that module might be a Server Component but if it's "use client" then importing that same file will be a Client Reference again. So you don't need some way to do the rewriting.

Copy link
Contributor

@hoxyq hoxyq left a comment

Choose a reason for hiding this comment

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

LGTM from the approach side, passing it to someone who has more context on Flight

Comment on lines +1278 to +1280
// Reset the task's thenable state before continuing. If there was one, it was
// from suspending the lazy before.
task.thenableState = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a silly question, but why adding / changing debugInfo has side-effects on task.thenableState?
Or is it just a small drive-by fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, it's mainly a drive-by fix. The bug was introduced in #28068

Comment on lines +205 to +206
// DEV-only
environmentName: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we make this field optional?

This could backfire once someone decides to use this field and not actually inspecting the type definition.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah personally I'd prefer we any cast the one place we read the name than do this to the Request type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have had this pattern elsewhere. It's nice because there's only one place to mess it up.

There will be many more places where environmentName gets used but the Request type is only initialized in one place.

Optional fields are bad for perf when you do mess them up because it breaks the hidden class. You could potentially accidentally add a field by writing to it unconditionally.

I don't like that we use optional fields for Fiber for example because we instead have bugs in the continued working with the code by doing undefined checks, which lets things pass and keep working even if they're undefined or missing. We typically check for example === null exactly so that if we get an undefined flowing through the system it should error. Even if that errors only in production because then we'll quickly find the mistake.

Comment on lines +205 to +206
// DEV-only
environmentName: string,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah personally I'd prefer we any cast the one place we read the name than do this to the Request type

if (debugID === null) {
// We don't have a chunk to assign debug info. We need to outline this
// component to assign it an ID.
return outlineTask(request, task);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems unfortunate that we fork the dev/prod behavior here. Means we need to have faith that outlining won't hide or express bugs that won't happen absent the debugInfo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well it would show up in prod. As long as it's unobservable it doesn't affect dev/prod behavior for users. At some point we just have to trust that we don't mess up the implementation.

@sebmarkbage sebmarkbage merged commit 629541b into facebook:main Feb 12, 2024
36 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 12, 2024
)

A Flight Server can be a consumer of a stream from another Server. In
this case the meta data is attached to debugInfo properties on lazy,
Promises, Arrays or Elements that might in turn get forwarded to the
next stream. In this case we want to forward this debug information to
the client in the stream.

I also added a DEV only `environmentName` option to the Flight Server.
This lets you name the server that is producing the debug info so that
you can trace the origin of where that component is executing. This
defaults to `"server"`. DevTools could use this for badges or different
colors.

DiffTrain build for [629541b](629541b)
huozhi added a commit to vercel/next.js that referenced this pull request Feb 23, 2024
### React upstream changes

- facebook/react#28333
- facebook/react#28334
- facebook/react#28378
- facebook/react#28377
- facebook/react#28376
- facebook/react#28338
- facebook/react#28331
- facebook/react#28336
- facebook/react#28320
- facebook/react#28317
- facebook/react#28375
- facebook/react#28367
- facebook/react#28380
- facebook/react#28368
- facebook/react#28343
- facebook/react#28355
- facebook/react#28374
- facebook/react#28362
- facebook/react#28344
- facebook/react#28339
- facebook/react#28353
- facebook/react#28346
- facebook/react#25790
- facebook/react#28352
- facebook/react#28326
- facebook/react#27688
- facebook/react#28329
- facebook/react#28332
- facebook/react#28340
- facebook/react#28327
- facebook/react#28325
- facebook/react#28324
- facebook/react#28309
- facebook/react#28310
- facebook/react#28307
- facebook/react#28306
- facebook/react#28315
- facebook/react#28318
- facebook/react#28226
- facebook/react#28308
- facebook/react#27563
- facebook/react#28297
- facebook/react#28286
- facebook/react#28284
- facebook/react#28275
- facebook/react#28145
- facebook/react#28301
- facebook/react#28224
- facebook/react#28152
- facebook/react#28296
- facebook/react#28294
- facebook/react#28279
- facebook/react#28273
- facebook/react#28269
- facebook/react#28376
- facebook/react#28338
- facebook/react#28331
- facebook/react#28336
- facebook/react#28320
- facebook/react#28317
- facebook/react#28375
- facebook/react#28367
- facebook/react#28380
- facebook/react#28368
- facebook/react#28343
- facebook/react#28355
- facebook/react#28374
- facebook/react#28362
- facebook/react#28344
- facebook/react#28339
- facebook/react#28353
- facebook/react#28346
- facebook/react#25790
- facebook/react#28352
- facebook/react#28326
- facebook/react#27688
- facebook/react#28329
- facebook/react#28332
- facebook/react#28340
- facebook/react#28327
- facebook/react#28325
- facebook/react#28324
- facebook/react#28309
- facebook/react#28310
- facebook/react#28307
- facebook/react#28306
- facebook/react#28315
- facebook/react#28318
- facebook/react#28226
- facebook/react#28308
- facebook/react#27563
- facebook/react#28297
- facebook/react#28286
- facebook/react#28284
- facebook/react#28275
- facebook/react#28145
- facebook/react#28301
- facebook/react#28224
- facebook/react#28152
- facebook/react#28296
- facebook/react#28294
- facebook/react#28279
- facebook/react#28273
- facebook/react#28269

Closes NEXT-2542


Disable ppr test for strict mode for now, @acdlite will check it and
we'll sync again
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
…ebook#28275)

A Flight Server can be a consumer of a stream from another Server. In
this case the meta data is attached to debugInfo properties on lazy,
Promises, Arrays or Elements that might in turn get forwarded to the
next stream. In this case we want to forward this debug information to
the client in the stream.

I also added a DEV only `environmentName` option to the Flight Server.
This lets you name the server that is producing the debug info so that
you can trace the origin of where that component is executing. This
defaults to `"server"`. DevTools could use this for badges or different
colors.
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
)

A Flight Server can be a consumer of a stream from another Server. In
this case the meta data is attached to debugInfo properties on lazy,
Promises, Arrays or Elements that might in turn get forwarded to the
next stream. In this case we want to forward this debug information to
the client in the stream.

I also added a DEV only `environmentName` option to the Flight Server.
This lets you name the server that is producing the debug info so that
you can trace the origin of where that component is executing. This
defaults to `"server"`. DevTools could use this for badges or different
colors.

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

7 participants