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

Warn for invalid type in renderer with the correct RSC stack #30102

Merged
merged 8 commits into from
Jun 27, 2024

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Jun 26, 2024

This is all behind the enableOwnerStacks flag.

This is a follow up to #29088. In that I moved type validation into the renderer since that's the one that knows what types are allowed. However, I only removed it from React.createElement and not the JSX which was an oversight.

However, I also noticed that for invalid types we don't have the right stack trace for throws because we're not yet inside the JSX element that itself is invalid. We should use its stack for the stack trace. That's the reason it's enough to just use the throw now because we can get a good stack trace from the owner stack. This is fixed by creating a fake Throw Fiber that gets assigned the right stack.

Additionally, I noticed that for certain invalid types like the most common one undefined we error in Flight so a missing import in RSC leads to a generic error. Instead of erroring on the Flight side we should just let anything that's not a Server Component through to the client and then let the Client renderer determine whether it's a valid type or not. Since we now have owner stacks through the server too, this will still be able to provide a good stack trace on the client that points to the server in that case.

Screenshot 2024-06-25 at 6 46 35 PM

To get the best stack you have to expand the little icon and the regular stack is noisy due to this Chrome bug which makes it a little harder to find but once that's fixed it might be easier.

Copy link

vercel bot commented Jun 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2024 5:45pm

@react-sizebot
Copy link

react-sizebot commented Jun 26, 2024

Comparing: 349a99a...213d584

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.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.01% 497.93 kB 497.99 kB +0.01% 89.26 kB 89.27 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.01% 502.75 kB 502.81 kB +0.01% 89.96 kB 89.97 kB
facebook-www/ReactDOM-prod.classic.js = 597.10 kB 597.08 kB +0.03% 105.31 kB 105.34 kB
facebook-www/ReactDOM-prod.modern.js = 571.44 kB 571.42 kB +0.03% 101.24 kB 101.27 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.react-server.development.js = 15.71 kB 12.83 kB = 4.12 kB 3.49 kB
oss-experimental/react/cjs/react-jsx-runtime.react-server.development.js = 15.71 kB 12.83 kB = 4.12 kB 3.49 kB
oss-experimental/react/cjs/react-jsx-runtime.development.js = 15.07 kB 12.19 kB = 3.99 kB 3.36 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.development.js = 14.87 kB 12.00 kB = 3.97 kB 3.34 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 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-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js = 127.78 kB 127.40 kB = 23.69 kB 23.67 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js = 127.78 kB 127.40 kB = 23.69 kB 23.67 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js = 127.78 kB 127.40 kB = 23.69 kB 23.67 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js = 127.63 kB 127.25 kB = 23.63 kB 23.61 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js = 127.63 kB 127.25 kB = 23.63 kB 23.61 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js = 127.63 kB 127.25 kB = 23.63 kB 23.61 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js = 126.69 kB 126.30 kB = 23.43 kB 23.41 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js = 126.69 kB 126.30 kB = 23.43 kB 23.41 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js = 126.69 kB 126.30 kB = 23.43 kB 23.41 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js = 126.52 kB 126.14 kB = 23.37 kB 23.35 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js = 126.52 kB 126.14 kB = 23.37 kB 23.35 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js = 126.52 kB 126.14 kB = 23.37 kB 23.35 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js = 125.03 kB 124.65 kB = 23.25 kB 23.23 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js = 125.03 kB 124.65 kB = 23.25 kB 23.23 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js = 125.03 kB 124.65 kB = 23.25 kB 23.23 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js = 124.88 kB 124.50 kB = 23.19 kB 23.17 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js = 124.88 kB 124.50 kB = 23.19 kB 23.17 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js = 124.88 kB 124.50 kB = 23.19 kB 23.17 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js = 124.67 kB 124.29 kB = 23.19 kB 23.17 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js = 124.67 kB 124.29 kB = 23.19 kB 23.17 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js = 124.67 kB 124.29 kB = 23.19 kB 23.17 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js = 124.05 kB 123.67 kB = 23.02 kB 22.99 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js = 124.05 kB 123.67 kB = 23.02 kB 22.99 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js = 124.05 kB 123.67 kB = 23.02 kB 22.99 kB
oss-stable-rc/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js = 120.34 kB 119.96 kB = 22.44 kB 22.41 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js = 120.34 kB 119.96 kB = 22.44 kB 22.41 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js = 120.34 kB 119.96 kB = 22.44 kB 22.41 kB
oss-stable-rc/react-server/cjs/react-server-flight.development.js = 80.50 kB 80.22 kB = 14.95 kB 14.93 kB
oss-stable-semver/react-server/cjs/react-server-flight.development.js = 80.50 kB 80.22 kB = 14.95 kB 14.93 kB
oss-stable/react-server/cjs/react-server-flight.development.js = 80.50 kB 80.22 kB = 14.95 kB 14.93 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.production.js = 96.62 kB 96.22 kB = 19.76 kB 19.70 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.js = 96.59 kB 96.19 kB = 19.77 kB 19.71 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.production.js = 95.66 kB 95.26 kB = 19.56 kB 19.49 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.js = 95.64 kB 95.24 kB = 19.55 kB 19.49 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.production.js = 93.60 kB 93.20 kB = 19.19 kB 19.14 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js = 93.57 kB 93.17 kB = 19.19 kB 19.14 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.js = 93.47 kB 93.07 kB = 19.17 kB 19.11 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.production.js = 93.15 kB 92.75 kB = 19.08 kB 19.02 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.production.js = 92.99 kB 92.59 kB = 19.11 kB 19.05 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.production.js = 92.99 kB 92.59 kB = 19.11 kB 19.05 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.production.js = 92.99 kB 92.59 kB = 19.11 kB 19.05 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.js = 92.96 kB 92.56 kB = 19.12 kB 19.06 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.js = 92.96 kB 92.56 kB = 19.12 kB 19.06 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.js = 92.96 kB 92.56 kB = 19.12 kB 19.06 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.production.js = 92.03 kB 91.63 kB = 18.90 kB 18.84 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.production.js = 92.03 kB 91.63 kB = 18.90 kB 18.84 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.production.js = 92.03 kB 91.63 kB = 18.90 kB 18.84 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.js = 92.02 kB 91.62 kB = 18.90 kB 18.83 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.js = 92.02 kB 91.62 kB = 18.90 kB 18.83 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.production.js = 92.02 kB 91.62 kB = 18.90 kB 18.83 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.js = 90.15 kB 89.75 kB = 18.69 kB 18.63 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.production.js = 89.84 kB 89.44 kB = 18.53 kB 18.47 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.production.js = 89.84 kB 89.44 kB = 18.53 kB 18.47 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.production.js = 89.84 kB 89.44 kB = 18.53 kB 18.47 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js = 89.82 kB 89.42 kB = 18.53 kB 18.48 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js = 89.82 kB 89.42 kB = 18.53 kB 18.48 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.production.js = 89.82 kB 89.42 kB = 18.53 kB 18.48 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.js = 89.80 kB 89.40 kB = 18.51 kB 18.46 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.js = 89.80 kB 89.40 kB = 18.51 kB 18.46 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.js = 89.80 kB 89.40 kB = 18.51 kB 18.46 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.production.js = 89.48 kB 89.08 kB = 18.41 kB 18.36 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.production.js = 89.48 kB 89.08 kB = 18.41 kB 18.36 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.production.js = 89.48 kB 89.08 kB = 18.41 kB 18.36 kB
oss-stable-rc/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.js = 86.53 kB 86.13 kB = 18.02 kB 17.97 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.js = 86.53 kB 86.13 kB = 18.02 kB 17.97 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.js = 86.53 kB 86.13 kB = 18.02 kB 17.97 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js = 139.96 kB 139.18 kB = 26.00 kB 25.91 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.development.js = 139.81 kB 139.03 kB = 25.95 kB 25.85 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.unbundled.development.js = 138.87 kB 138.09 kB = 25.75 kB 25.66 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.node.unbundled.development.js = 138.70 kB 137.92 kB = 25.69 kB 25.60 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.edge.development.js = 137.40 kB 136.62 kB = 25.57 kB 25.48 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.edge.development.js = 137.25 kB 136.47 kB = 25.51 kB 25.42 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js = 136.71 kB 135.93 kB = 25.47 kB 25.38 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-server.browser.development.js = 136.08 kB 135.30 kB = 25.30 kB 25.21 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js = 132.52 kB 131.74 kB = 24.75 kB 24.66 kB
oss-experimental/react-server/cjs/react-server-flight.production.js = 59.49 kB 59.13 kB = 11.88 kB 11.86 kB
oss-stable-rc/react-server/cjs/react-server-flight.production.js = 55.53 kB 55.17 kB = 11.16 kB 11.14 kB
oss-stable-semver/react-server/cjs/react-server-flight.production.js = 55.53 kB 55.17 kB = 11.16 kB 11.14 kB
oss-stable/react-server/cjs/react-server-flight.production.js = 55.53 kB 55.17 kB = 11.16 kB 11.14 kB
oss-experimental/react-server/cjs/react-server-flight.development.js = 92.53 kB 91.89 kB = 17.15 kB 17.06 kB
oss-experimental/react/cjs/react.development.js = 46.79 kB 46.28 kB = 10.69 kB 10.61 kB
oss-experimental/react/cjs/react.react-server.development.js = 37.34 kB 36.83 kB = 8.80 kB 8.72 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.react-server.development.js = 15.71 kB 12.83 kB = 4.12 kB 3.49 kB
oss-experimental/react/cjs/react-jsx-runtime.react-server.development.js = 15.71 kB 12.83 kB = 4.12 kB 3.49 kB
oss-experimental/react/cjs/react-jsx-runtime.development.js = 15.07 kB 12.19 kB = 3.99 kB 3.36 kB
oss-experimental/react/cjs/react-jsx-dev-runtime.development.js = 14.87 kB 12.00 kB = 3.97 kB 3.34 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Generated by 🚫 dangerJS against 213d584

This lets us delete more of this code once it lands fully.
In particular the hard coded client reference is no longer needed.
We'll handle this in the reconciler instead with the proper stack traces.
This ensures that we transfer the stack/owner from the element to the new
Fiber.
Covered in the ReactComponent-test
We let the client decide if it's valid or not and provide the error message if not.
This gets serialized as a tuple in the Flight protocol so we think it needs
a key but it doesn't. It'll error later on the client.

Fix test asserting lazy because it's not actually executing the rendering
pass on the client since the transport is not live in Noop.

Technically this doesn't error if the Shared Component renders something
that can be a type since we actually resolve this component as if it is
just some value.
It breaks the other tests.
@huozhi
Copy link
Contributor

huozhi commented Jun 27, 2024

:shipit:

@sebmarkbage sebmarkbage merged commit e02baf6 into facebook:main Jun 27, 2024
138 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 27, 2024
This is all behind the `enableOwnerStacks` flag.

This is a follow up to #29088. In that I moved type validation into the
renderer since that's the one that knows what types are allowed.
However, I only removed it from `React.createElement` and not the JSX
which was an oversight.

However, I also noticed that for invalid types we don't have the right
stack trace for throws because we're not yet inside the JSX element that
itself is invalid. We should use its stack for the stack trace. That's
the reason it's enough to just use the throw now because we can get a
good stack trace from the owner stack. This is fixed by creating a fake
Throw Fiber that gets assigned the right stack.

Additionally, I noticed that for certain invalid types like the most
common one `undefined` we error in Flight so a missing import in RSC
leads to a generic error. Instead of erroring on the Flight side we
should just let anything that's not a Server Component through to the
client and then let the Client renderer determine whether it's a valid
type or not. Since we now have owner stacks through the server too, this
will still be able to provide a good stack trace on the client that
points to the server in that case.

<img width="571" alt="Screenshot 2024-06-25 at 6 46 35 PM"
src="https://github.com/facebook/react/assets/63648/6812c24f-e274-4e09-b4de-21deda9ea1d4">

To get the best stack you have to expand the little icon and the regular
stack is noisy [due to this Chrome
bug](https://issues.chromium.org/issues/345248263) which makes it a
little harder to find but once that's fixed it might be easier.

DiffTrain build for commit e02baf6.
github-actions bot pushed a commit that referenced this pull request Jun 27, 2024
This is all behind the `enableOwnerStacks` flag.

This is a follow up to #29088. In that I moved type validation into the
renderer since that's the one that knows what types are allowed.
However, I only removed it from `React.createElement` and not the JSX
which was an oversight.

However, I also noticed that for invalid types we don't have the right
stack trace for throws because we're not yet inside the JSX element that
itself is invalid. We should use its stack for the stack trace. That's
the reason it's enough to just use the throw now because we can get a
good stack trace from the owner stack. This is fixed by creating a fake
Throw Fiber that gets assigned the right stack.

Additionally, I noticed that for certain invalid types like the most
common one `undefined` we error in Flight so a missing import in RSC
leads to a generic error. Instead of erroring on the Flight side we
should just let anything that's not a Server Component through to the
client and then let the Client renderer determine whether it's a valid
type or not. Since we now have owner stacks through the server too, this
will still be able to provide a good stack trace on the client that
points to the server in that case.

<img width="571" alt="Screenshot 2024-06-25 at 6 46 35 PM"
src="https://github.com/facebook/react/assets/63648/6812c24f-e274-4e09-b4de-21deda9ea1d4">

To get the best stack you have to expand the little icon and the regular
stack is noisy [due to this Chrome
bug](https://issues.chromium.org/issues/345248263) which makes it a
little harder to find but once that's fixed it might be easier.

DiffTrain build for [e02baf6](e02baf6)
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