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

Badge Environment Name on Thrown Errors from the Server #29846

Merged
merged 10 commits into from
Jun 26, 2024

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Jun 11, 2024

When we replay logs we badge them with e.g. [Server]. That way it's easy to identify that the source of the log actually happened on the Server (RSC). However, when we threw an error we didn't have any such thing. The error was rethrown on the client and then handled just like any other client error.

This transfers the environmentName in DEV to our restored Error "sub-class" (conceptually) along with digest. That way you can read error.environmentName to print this in your own UI.

I also updated our default for onCaughtError (and onError in Fizz) to use the printToConsole helper that the Flight Client uses to log it with the badge format. So by default you get the same experience as console.error for caught errors:

Screenshot 2024-06-10 at 9 25 12 PM Screenshot 2024-06-10 at 9 39 30 PM

Unfortunately I can't do the same thing for onUncaughtError nor onRecoverableError because they use reportError which doesn't have custom formatting (unless we also prevented default on window.onerror). However maybe that's ok because 1) you should always have an error boundary 2) it's not likely that an RSC error can actually recover because it's not going to be rendered again so shouldn't really happen outside some parent conditionally rendering maybe.

The other problem with this approach is that the default is no longer trivial - so reimplementing the default in user space is trickier and ideally we shouldn't expose our default to be called.

Copy link

vercel bot commented Jun 11, 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:21pm

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

react-sizebot commented Jun 11, 2024

Comparing: ef0f44e...d31e852

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 +0.11% 1.82 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 497.93 kB 497.93 kB = 89.26 kB 89.26 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB +0.11% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 502.75 kB 502.75 kB = 89.96 kB 89.96 kB
facebook-www/ReactDOM-prod.classic.js = 597.10 kB 597.10 kB = 105.31 kB 105.31 kB
facebook-www/ReactDOM-prod.modern.js = 571.44 kB 571.44 kB = 101.24 kB 101.24 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-esm/cjs/react-server-dom-esm-client.browser.development.js +0.95% 69.40 kB 70.06 kB +0.84% 12.91 kB 13.02 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +0.95% 69.40 kB 70.06 kB +0.84% 12.91 kB 13.02 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +0.95% 69.40 kB 70.06 kB +0.84% 12.91 kB 13.02 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +0.93% 71.24 kB 71.90 kB +0.80% 13.31 kB 13.41 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +0.93% 71.24 kB 71.90 kB +0.80% 13.31 kB 13.41 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +0.93% 71.24 kB 71.90 kB +0.80% 13.31 kB 13.41 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +0.92% 71.70 kB 72.36 kB +0.92% 13.41 kB 13.54 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +0.92% 71.70 kB 72.36 kB +0.92% 13.41 kB 13.54 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +0.92% 71.70 kB 72.36 kB +0.92% 13.41 kB 13.54 kB
oss-stable-rc/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +0.89% 74.34 kB 75.00 kB +0.84% 13.99 kB 14.11 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +0.89% 74.34 kB 75.00 kB +0.84% 13.99 kB 14.11 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +0.89% 74.34 kB 75.00 kB +0.84% 13.99 kB 14.11 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +0.89% 75.47 kB 76.13 kB +0.71% 14.42 kB 14.52 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +0.87% 75.74 kB 76.40 kB +0.87% 14.30 kB 14.43 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +0.87% 75.74 kB 76.40 kB +0.87% 14.30 kB 14.43 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +0.87% 75.74 kB 76.40 kB +0.87% 14.30 kB 14.43 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +0.87% 75.75 kB 76.41 kB +0.85% 14.31 kB 14.43 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +0.87% 75.75 kB 76.41 kB +0.85% 14.31 kB 14.43 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +0.87% 75.75 kB 76.41 kB +0.85% 14.31 kB 14.43 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +0.86% 77.31 kB 77.98 kB +0.76% 14.81 kB 14.92 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +0.86% 76.53 kB 77.19 kB +0.92% 14.49 kB 14.62 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +0.86% 76.53 kB 77.19 kB +0.92% 14.49 kB 14.62 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +0.86% 76.53 kB 77.19 kB +0.92% 14.49 kB 14.62 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +0.86% 76.55 kB 77.21 kB +0.94% 14.47 kB 14.60 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +0.86% 76.55 kB 77.21 kB +0.94% 14.47 kB 14.60 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +0.86% 76.55 kB 77.21 kB +0.94% 14.47 kB 14.60 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +0.86% 77.76 kB 78.43 kB +0.80% 14.93 kB 15.05 kB
oss-stable-rc/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +0.85% 77.91 kB 78.57 kB +0.90% 14.71 kB 14.84 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +0.85% 77.91 kB 78.57 kB +0.90% 14.71 kB 14.84 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +0.85% 77.91 kB 78.57 kB +0.90% 14.71 kB 14.84 kB
oss-stable-rc/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +0.85% 77.93 kB 78.59 kB +0.93% 14.68 kB 14.82 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +0.85% 77.93 kB 78.59 kB +0.93% 14.68 kB 14.82 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +0.85% 77.93 kB 78.59 kB +0.93% 14.68 kB 14.82 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +0.83% 80.40 kB 81.07 kB +0.87% 15.40 kB 15.53 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +0.82% 81.81 kB 82.48 kB +0.89% 15.72 kB 15.86 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +0.82% 81.81 kB 82.48 kB +0.88% 15.73 kB 15.87 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +0.81% 82.60 kB 83.27 kB +0.90% 15.90 kB 16.04 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +0.81% 82.61 kB 83.28 kB +0.92% 15.88 kB 16.02 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +0.80% 83.98 kB 84.65 kB +0.88% 16.17 kB 16.31 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +0.80% 83.99 kB 84.66 kB +0.90% 16.14 kB 16.29 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +0.71% 107.79 kB 108.56 kB +0.87% 24.28 kB 24.49 kB
oss-stable-rc/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +0.65% 98.55 kB 99.19 kB +0.74% 21.76 kB 21.92 kB
oss-stable-semver/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +0.65% 98.55 kB 99.19 kB +0.74% 21.76 kB 21.92 kB
oss-stable/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +0.65% 98.55 kB 99.19 kB +0.74% 21.76 kB 21.92 kB
oss-experimental/react-dom/cjs/react-dom-server.bun.production.js +0.51% 219.18 kB 220.30 kB +0.73% 39.83 kB 40.12 kB
oss-stable-rc/react-dom/cjs/react-dom-server.bun.production.js +0.50% 202.96 kB 203.97 kB +0.75% 37.68 kB 37.96 kB
oss-stable-semver/react-dom/cjs/react-dom-server.bun.production.js +0.50% 202.96 kB 203.97 kB +0.75% 37.68 kB 37.96 kB
oss-stable/react-dom/cjs/react-dom-server.bun.production.js +0.50% 203.03 kB 204.03 kB +0.75% 37.70 kB 37.99 kB
oss-stable-rc/react-dom/cjs/react-dom-server.node.production.js +0.49% 215.15 kB 216.21 kB +0.76% 39.49 kB 39.79 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node.production.js +0.49% 215.15 kB 216.21 kB +0.76% 39.49 kB 39.79 kB
oss-stable/react-dom/cjs/react-dom-server.node.production.js +0.49% 215.22 kB 216.28 kB +0.76% 39.51 kB 39.81 kB
facebook-www/ReactDOMServerStreaming-prod.modern.js +0.49% 210.99 kB 212.03 kB +0.70% 39.14 kB 39.42 kB
oss-experimental/react-dom/cjs/react-dom-server.node.production.js +0.49% 240.33 kB 241.50 kB +0.74% 43.04 kB 43.36 kB
oss-stable-rc/react-dom/cjs/react-dom-server.edge.production.js +0.48% 219.29 kB 220.35 kB +0.73% 40.73 kB 41.03 kB
oss-stable-semver/react-dom/cjs/react-dom-server.edge.production.js +0.48% 219.29 kB 220.35 kB +0.73% 40.73 kB 41.03 kB
oss-stable/react-dom/cjs/react-dom-server.edge.production.js +0.48% 219.36 kB 220.42 kB +0.74% 40.76 kB 41.06 kB
oss-experimental/react-dom/cjs/react-dom-server.edge.production.js +0.48% 244.38 kB 245.55 kB +0.73% 43.79 kB 44.11 kB
oss-stable-rc/react-dom/cjs/react-dom-server.browser.production.js +0.47% 214.42 kB 215.43 kB +0.70% 38.90 kB 39.17 kB
oss-stable-semver/react-dom/cjs/react-dom-server.browser.production.js +0.47% 214.42 kB 215.43 kB +0.70% 38.90 kB 39.17 kB
oss-stable/react-dom/cjs/react-dom-server.browser.production.js +0.47% 214.49 kB 215.50 kB +0.70% 38.93 kB 39.20 kB
oss-experimental/react-dom/cjs/react-dom-server.browser.production.js +0.47% 238.96 kB 240.08 kB +0.73% 41.84 kB 42.14 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer.production.js +0.33% 34.95 kB 35.07 kB +0.55% 6.55 kB 6.58 kB
oss-stable-rc/react-noop-renderer/cjs/react-noop-renderer.production.js +0.33% 34.95 kB 35.07 kB +0.55% 6.55 kB 6.58 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer.production.js +0.33% 34.95 kB 35.07 kB +0.55% 6.55 kB 6.58 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer.production.js +0.33% 34.95 kB 35.07 kB +0.55% 6.55 kB 6.58 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-persistent.production.js +0.33% 35.08 kB 35.20 kB +0.55% 6.57 kB 6.60 kB
oss-stable-rc/react-noop-renderer/cjs/react-noop-renderer-persistent.production.js +0.33% 35.08 kB 35.20 kB +0.55% 6.57 kB 6.60 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-persistent.production.js +0.33% 35.08 kB 35.20 kB +0.55% 6.57 kB 6.60 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-persistent.production.js +0.33% 35.08 kB 35.20 kB +0.55% 6.57 kB 6.60 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.browser.production.js +0.33% 213.64 kB 214.34 kB +0.54% 38.63 kB 38.84 kB
oss-stable-rc/react-dom/cjs/react-dom-server.bun.development.js +0.32% 302.48 kB 303.46 kB +0.39% 59.40 kB 59.63 kB
oss-stable-semver/react-dom/cjs/react-dom-server.bun.development.js +0.32% 302.48 kB 303.46 kB +0.39% 59.40 kB 59.63 kB
oss-stable/react-dom/cjs/react-dom-server.bun.development.js +0.32% 302.55 kB 303.53 kB +0.38% 59.42 kB 59.65 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.node.production.js +0.32% 218.63 kB 219.33 kB +0.53% 40.48 kB 40.69 kB
oss-stable-rc/react-noop-renderer/cjs/react-noop-renderer.development.js +0.31% 39.51 kB 39.64 kB +0.48% 7.30 kB 7.33 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer.development.js +0.31% 39.51 kB 39.64 kB +0.48% 7.30 kB 7.33 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer.development.js +0.31% 39.51 kB 39.64 kB +0.48% 7.30 kB 7.33 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer.development.js +0.31% 39.59 kB 39.72 kB +0.48% 7.32 kB 7.36 kB
oss-stable-rc/react-noop-renderer/cjs/react-noop-renderer-persistent.development.js +0.31% 39.65 kB 39.78 kB +0.48% 7.32 kB 7.35 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-persistent.development.js +0.31% 39.65 kB 39.78 kB +0.48% 7.32 kB 7.35 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-persistent.development.js +0.31% 39.65 kB 39.78 kB +0.48% 7.32 kB 7.35 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-persistent.development.js +0.31% 39.73 kB 39.86 kB +0.48% 7.34 kB 7.38 kB
oss-experimental/react-dom/cjs/react-dom-server.bun.development.js +0.30% 321.97 kB 322.94 kB +0.38% 62.04 kB 62.27 kB
oss-stable-rc/react-dom/cjs/react-dom-server-legacy.browser.production.js +0.30% 199.08 kB 199.68 kB +0.48% 36.63 kB 36.81 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.browser.production.js +0.30% 199.08 kB 199.68 kB +0.48% 36.63 kB 36.81 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.browser.production.js +0.30% 199.11 kB 199.70 kB +0.49% 36.65 kB 36.83 kB
oss-stable-rc/react-dom/cjs/react-dom-server.node.development.js +0.29% 347.97 kB 348.99 kB +0.38% 62.98 kB 63.22 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node.development.js +0.29% 347.97 kB 348.99 kB +0.38% 62.98 kB 63.22 kB
oss-stable/react-dom/cjs/react-dom-server.node.development.js +0.29% 348.04 kB 349.06 kB +0.39% 63.00 kB 63.24 kB
oss-stable-rc/react-dom/cjs/react-dom-server-legacy.node.production.js +0.29% 203.52 kB 204.11 kB +0.47% 38.37 kB 38.55 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.node.production.js +0.29% 203.52 kB 204.11 kB +0.47% 38.37 kB 38.55 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.node.production.js +0.29% 203.55 kB 204.14 kB +0.47% 38.39 kB 38.58 kB
oss-stable-rc/react-dom/cjs/react-dom-server.edge.development.js +0.29% 353.38 kB 354.40 kB +0.41% 64.35 kB 64.61 kB
oss-stable-semver/react-dom/cjs/react-dom-server.edge.development.js +0.29% 353.38 kB 354.40 kB +0.41% 64.35 kB 64.61 kB
oss-stable/react-dom/cjs/react-dom-server.edge.development.js +0.29% 353.45 kB 354.47 kB +0.41% 64.38 kB 64.64 kB
facebook-www/ReactDOMServer-prod.modern.js +0.29% 206.74 kB 207.33 kB +0.45% 37.71 kB 37.88 kB
facebook-www/ReactDOMServer-prod.classic.js +0.29% 207.39 kB 207.98 kB +0.46% 37.92 kB 38.09 kB
facebook-www/ReactDOMServerStreaming-dev.modern.js +0.28% 345.36 kB 346.33 kB +0.40% 62.68 kB 62.93 kB
oss-stable-rc/react-dom/cjs/react-dom-server.browser.development.js +0.27% 352.89 kB 353.85 kB +0.38% 64.28 kB 64.52 kB
oss-stable-semver/react-dom/cjs/react-dom-server.browser.development.js +0.27% 352.89 kB 353.85 kB +0.38% 64.28 kB 64.52 kB
oss-stable/react-dom/cjs/react-dom-server.browser.development.js +0.27% 352.96 kB 353.92 kB +0.38% 64.30 kB 64.55 kB
oss-experimental/react-dom/cjs/react-dom-server.node.development.js +0.27% 379.84 kB 380.86 kB +0.36% 67.24 kB 67.48 kB
oss-experimental/react-dom/cjs/react-dom-server.edge.development.js +0.26% 384.91 kB 385.93 kB +0.38% 67.82 kB 68.08 kB
oss-experimental/react-dom/cjs/react-dom-server.browser.development.js +0.25% 384.42 kB 385.38 kB +0.34% 67.75 kB 67.98 kB
oss-stable-rc/react-server/cjs/react-server.production.js +0.20% 106.03 kB 106.25 kB +0.33% 19.41 kB 19.48 kB
oss-stable-semver/react-server/cjs/react-server.production.js +0.20% 106.03 kB 106.25 kB +0.33% 19.41 kB 19.48 kB
oss-stable/react-server/cjs/react-server.production.js +0.20% 106.03 kB 106.25 kB +0.33% 19.41 kB 19.48 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Generated by 🚫 dangerJS against d31e852

try {
if (error instanceof Error) {
// eslint-disable-next-line react-internal/safe-string-coercion
message = String(error.message);
stack = getStack(error);
const errorEnv = (error: any).environmentName;
if (typeof errorEnv === 'string') {
// This probably came from another FlightClient as a pass through.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This probably came from another FlightClient as a pass through.
// This probably came from another FlightServer as a pass through.

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, technically what I mean is that the FlightClient is what creates the object on the parsing side. In theory it wasn't necessarily even from a FlightServer that generated the payload.

Conceptually it's a bit unclear who hides the original thrown/rejected value (which might not be an Error) and who creates the new Error - FlightServer or FlightClient? I guess FlightServer. We don't technically serialize Error objects - we serialize the throw.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, technically what I mean is that the FlightClient is what creates the object on the parsing side.

Do you mean this line? How would this end up back in a Flight Server?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the server-to-server case where an RSC server consumes the payload from another RSC server (not the binary pass-though case). I.e. the case we have in our tests.

Copy link
Contributor

@unstubbable unstubbable Jun 11, 2024

Choose a reason for hiding this comment

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

Oh, of course, I forgot that there must be a client in-between in the server-to-server case. 🤦

args,
expectedArgCount: argIndex,
});
if (format.includes('%c%s')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this mirror the check in shouldIgnoreConsoleError i.e.

Suggested change
if (format.includes('%c%s')) {
if (format.startsWith('%c%s%c')) {

or are these files unrelated?

To be honest, I don't quite follow why we need to ignore this case and why there's no good default for our test suite. Could you add test to packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js to illustrate what this is doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In shouldIgnoreConsoleError the more specific one was ok because we didn't test any paths that used the server printer:

https://github.com/sebmarkbage/react/blob/ba2389424a1deb617e62d8473e4c2e718a2ed984/packages/react-client/src/ReactClientConsoleConfigServer.js#L13

But tbh, none of this makes any sense. We should find a way to remove shouldIgnoreConsoleError. There must be some systemic issue in our tests that we can address so we don't need this anymore. I keep just hacking in whatever I need to keep it running.

Regarding the argument mismatch I feel like we should just remove this assertion. We've found a case where this is valid. So if we keep it we need some way to disable it. Isn't the lint warning enough for the common mistakes and we can disable the lint warning as needed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

But tbh, none of this makes any sense. We should find a way to remove shouldIgnoreConsoleError

I'm all for that. I just don't know which test hits this path so I can't help.

Isn't the lint warning enough for the common mistakes and we can disable the lint warning as needed?

It should be. Maybe the additional runtime check was for calls that aren't checked by the lint rule. I can double check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use the usual assertConsoleErrorDev for now but probably want a specific assertConsoleBadgedErrorDev in the future to encode the behavior clearer: sebmarkbage#6

@sebmarkbage
Copy link
Collaborator Author

@eps1lon @gnoff ping

@@ -94,13 +96,33 @@ export function defaultOnCaughtError(
}.`;

if (enableOwnerStacks) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I only added this feature to the enableOwnerStacks flag because we the other branch uses the uninstrumented console['error'](...) and we don't have a version of printToConsole that excludes adding a component stack. So to avoid forking all that behavior for the old branch I just made this a "new world" feature.

if (format.startsWith('%c%s')) {
// Looks like a badged error message
args.splice(0, 3);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is ensuring we're filtering the same as before. No change in what gets filtered.

This is attached to our custom Error "sub class" on the receiving side
which also includes digest.

DEV-only.
This way this helper can use component stacks when available.
That way your typical log of an error that originated on the Server gets
a `[Server]` badge.

Unfortunately because defaultOnUncaughtError and defaultOnRecoverableError
doesn't use custom logging but goes through reportError. There's no place
for us to add this kind of formatted badging to the logs.

It's also unfortunate that you'd have to replicate this in user space.
@sebmarkbage
Copy link
Collaborator Author

Felt cute. Might delete later.

This is inline with the current strategy already in main but another strategy might be to rely on Meta Frameworks to add this badge.

@sebmarkbage sebmarkbage merged commit 349a99a into facebook:main Jun 26, 2024
138 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 26, 2024
When we replay logs we badge them with e.g. `[Server]`. That way it's
easy to identify that the source of the log actually happened on the
Server (RSC). However, when we threw an error we didn't have any such
thing. The error was rethrown on the client and then handled just like
any other client error.

This transfers the `environmentName` in DEV to our restored Error
"sub-class" (conceptually) along with `digest`. That way you can read
`error.environmentName` to print this in your own UI.

I also updated our default for `onCaughtError` (and `onError` in Fizz)
to use the `printToConsole` helper that the Flight Client uses to log it
with the badge format. So by default you get the same experience as
console.error for caught errors:

<img width="810" alt="Screenshot 2024-06-10 at 9 25 12 PM"
src="https://github.com/facebook/react/assets/63648/8490fedc-09f6-4286-9332-fbe6b0faa2d3">

<img width="815" alt="Screenshot 2024-06-10 at 9 39 30 PM"
src="https://github.com/facebook/react/assets/63648/bdcfc554-504a-4b1d-82bf-b717e74975ac">

Unfortunately I can't do the same thing for `onUncaughtError` nor
`onRecoverableError` because they use `reportError` which doesn't have
custom formatting (unless we also prevented default on window.onerror).
However maybe that's ok because 1) you should always have an error
boundary 2) it's not likely that an RSC error can actually recover
because it's not going to be rendered again so shouldn't really happen
outside some parent conditionally rendering maybe.

The other problem with this approach is that the default is no longer
trivial - so reimplementing the default in user space is trickier and
ideally we shouldn't expose our default to be called.

DiffTrain build for [349a99a](349a99a)
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.

6 participants