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] Prefix Replayed Console Logs with a Badge #28403

Merged
merged 6 commits into from
Feb 21, 2024

Conversation

sebmarkbage
Copy link
Collaborator

Builds on top of #28384.

This prefixes each log with a badge similar to how we badge built-ins like "ForwardRef" and "Memo" in the React DevTools. The idea is that we can add such badges in DevTools for Server Components too to carry on the consistency.

This puts the "environment" name in the badge which defaults to "Server". So you know which source it is coming from.

We try to use the same styling as the React DevTools. We use light-dark mode where available to support the two different color styles, but if it's not available I use a fixed background so that it's always readable even in dark mode.

In Terminals, instead of hard coding colors that might not look good with some themes, I use the ANSI color code to flip background/foreground colors in that case.

In earlier commits I had it on the end of the line similar to the DevTools badges but for multiline I found it better to prefix it. We could try various options tough.

In most cases we can use both ANSI and the %c CSS color specifier, because node will only use ANSI and hide the other. Chrome supports both but the color overrides ANSI if it comes later (and Chrome doesn't support color inverting anyway). Safari/Firefox prints the ANSI, so it can only use CSS colors.

Therefore in browser builds I exclude ANSI.

On the server I support both so if you use Chrome inspector on the server, you get nice colors on both terminal and in the inspector.

Since Bun uses WebKit inspector and it prints the ANSI we can't safely emit both there. However, we also can't emit just the color specifier because then it prints in the terminal. oven-sh/bun#9021 So we just use a plain string prefix for now with a bracket until that's fixed.

Screen shots:

Screenshot 2024-02-21 at 12 56 02 AM Screenshot 2024-02-21 at 12 56 24 AM Screenshot 2024-02-21 at 12 57 10 AM Screenshot 2024-02-21 at 12 57 34 AM Screenshot 2024-02-21 at 12 58 23 AM Screenshot 2024-02-21 at 12 58 56 AM

@sebmarkbage sebmarkbage requested review from gnoff and hoxyq February 21, 2024 06:15
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 21, 2024
@react-sizebot
Copy link

react-sizebot commented Feb 21, 2024

Comparing: 9a5b6bd...525b3e5

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.86 kB 176.86 kB = 55.14 kB 55.14 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 179.00 kB 179.00 kB = 55.78 kB 55.78 kB
facebook-www/ReactDOM-prod.classic.js = 591.78 kB 591.78 kB = 104.51 kB 104.51 kB
facebook-www/ReactDOM-prod.modern.js = 575.07 kB 575.07 kB = 101.51 kB 101.51 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.js +9.60% 1.76 kB 1.93 kB +10.70% 0.78 kB 0.86 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.js +9.60% 1.76 kB 1.93 kB +10.70% 0.78 kB 0.86 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.js +9.60% 1.76 kB 1.93 kB +10.70% 0.78 kB 0.86 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-client.development.js +9.37% 1.91 kB 2.09 kB +10.39% 0.83 kB 0.91 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-client.development.js +9.37% 1.91 kB 2.09 kB +10.39% 0.83 kB 0.91 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-client.development.js +9.37% 1.91 kB 2.09 kB +10.39% 0.83 kB 0.91 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.min.js +5.82% 1.00 kB 1.05 kB +4.30% 0.54 kB 0.56 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.min.js +5.82% 1.00 kB 1.05 kB +4.30% 0.54 kB 0.56 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.min.js +5.82% 1.00 kB 1.05 kB +4.30% 0.54 kB 0.56 kB
facebook-www/ReactFlightDOMClient-dev.modern.js +2.73% 38.53 kB 39.58 kB +3.09% 8.90 kB 9.17 kB
oss-stable-semver/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.38% 55.62 kB 56.94 kB +3.13% 13.42 kB 13.84 kB
oss-stable/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.38% 55.62 kB 56.94 kB +3.13% 13.42 kB 13.84 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.37% 55.82 kB 57.14 kB +3.11% 13.49 kB 13.91 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.37% 55.82 kB 57.14 kB +3.11% 13.49 kB 13.91 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +2.24% 59.07 kB 60.39 kB +2.97% 14.46 kB 14.89 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +2.24% 59.07 kB 60.39 kB +2.97% 14.46 kB 14.89 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.23% 63.53 kB 64.94 kB +2.97% 15.40 kB 15.86 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.23% 63.53 kB 64.94 kB +2.97% 15.40 kB 15.86 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.22% 59.58 kB 60.90 kB +2.92% 14.64 kB 15.06 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.22% 59.58 kB 60.90 kB +2.92% 14.64 kB 15.06 kB
oss-stable-semver/react-server-dom-turbopack/umd/react-server-dom-turbopack-client.browser.development.js +2.22% 62.78 kB 64.17 kB +2.95% 14.69 kB 15.12 kB
oss-stable/react-server-dom-turbopack/umd/react-server-dom-turbopack-client.browser.development.js +2.22% 62.78 kB 64.17 kB +2.95% 14.69 kB 15.12 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.20% 63.32 kB 64.71 kB +2.93% 14.87 kB 15.30 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.20% 63.32 kB 64.71 kB +2.93% 14.87 kB 15.30 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.18% 60.70 kB 62.02 kB +2.91% 14.43 kB 14.85 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.17% 60.90 kB 62.23 kB +2.90% 14.49 kB 14.91 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +2.16% 65.31 kB 66.73 kB +3.02% 15.94 kB 16.42 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +2.16% 65.31 kB 66.73 kB +3.02% 15.94 kB 16.42 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.16% 65.35 kB 66.76 kB +3.02% 15.97 kB 16.45 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.16% 65.35 kB 66.76 kB +3.02% 15.97 kB 16.45 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +2.12% 66.75 kB 68.16 kB +2.92% 16.33 kB 16.81 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +2.12% 66.75 kB 68.16 kB +2.92% 16.33 kB 16.81 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.12% 66.77 kB 68.19 kB +2.90% 16.37 kB 16.85 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.12% 66.77 kB 68.19 kB +2.90% 16.37 kB 16.85 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +2.09% 67.61 kB 69.03 kB +2.89% 16.53 kB 17.01 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +2.09% 67.61 kB 69.03 kB +2.89% 16.53 kB 17.01 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.09% 67.64 kB 69.05 kB +2.87% 16.57 kB 17.05 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.09% 67.64 kB 69.05 kB +2.87% 16.57 kB 17.05 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.06% 68.62 kB 70.03 kB +2.80% 16.40 kB 16.86 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +2.06% 64.15 kB 65.48 kB +2.79% 15.46 kB 15.89 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.04% 64.66 kB 65.99 kB +2.72% 15.64 kB 16.06 kB
oss-experimental/react-server-dom-turbopack/umd/react-server-dom-turbopack-client.browser.development.js +2.04% 68.18 kB 69.57 kB +2.78% 15.71 kB 16.15 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.02% 68.72 kB 70.11 kB +2.74% 15.89 kB 16.33 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +2.01% 70.40 kB 71.81 kB +2.87% 16.95 kB 17.43 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.01% 70.43 kB 71.85 kB +2.85% 16.97 kB 17.45 kB
test_utils/ReactAllWarnings.js Deleted 66.50 kB 0.00 kB Deleted 16.27 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-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.js +9.60% 1.76 kB 1.93 kB +10.70% 0.78 kB 0.86 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.js +9.60% 1.76 kB 1.93 kB +10.70% 0.78 kB 0.86 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.js +9.60% 1.76 kB 1.93 kB +10.70% 0.78 kB 0.86 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-client.development.js +9.37% 1.91 kB 2.09 kB +10.39% 0.83 kB 0.91 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-client.development.js +9.37% 1.91 kB 2.09 kB +10.39% 0.83 kB 0.91 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-client.development.js +9.37% 1.91 kB 2.09 kB +10.39% 0.83 kB 0.91 kB
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.min.js +5.82% 1.00 kB 1.05 kB +4.30% 0.54 kB 0.56 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.min.js +5.82% 1.00 kB 1.05 kB +4.30% 0.54 kB 0.56 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-flight-client.production.min.js +5.82% 1.00 kB 1.05 kB +4.30% 0.54 kB 0.56 kB
facebook-www/ReactFlightDOMClient-dev.modern.js +2.73% 38.53 kB 39.58 kB +3.09% 8.90 kB 9.17 kB
oss-stable-semver/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.38% 55.62 kB 56.94 kB +3.13% 13.42 kB 13.84 kB
oss-stable/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.38% 55.62 kB 56.94 kB +3.13% 13.42 kB 13.84 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.37% 55.82 kB 57.14 kB +3.11% 13.49 kB 13.91 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.37% 55.82 kB 57.14 kB +3.11% 13.49 kB 13.91 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +2.24% 59.07 kB 60.39 kB +2.97% 14.46 kB 14.89 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +2.24% 59.07 kB 60.39 kB +2.97% 14.46 kB 14.89 kB
oss-stable-semver/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.23% 63.53 kB 64.94 kB +2.97% 15.40 kB 15.86 kB
oss-stable/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.23% 63.53 kB 64.94 kB +2.97% 15.40 kB 15.86 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.22% 59.58 kB 60.90 kB +2.92% 14.64 kB 15.06 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.22% 59.58 kB 60.90 kB +2.92% 14.64 kB 15.06 kB
oss-stable-semver/react-server-dom-turbopack/umd/react-server-dom-turbopack-client.browser.development.js +2.22% 62.78 kB 64.17 kB +2.95% 14.69 kB 15.12 kB
oss-stable/react-server-dom-turbopack/umd/react-server-dom-turbopack-client.browser.development.js +2.22% 62.78 kB 64.17 kB +2.95% 14.69 kB 15.12 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.20% 63.32 kB 64.71 kB +2.93% 14.87 kB 15.30 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.20% 63.32 kB 64.71 kB +2.93% 14.87 kB 15.30 kB
oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +2.18% 60.70 kB 62.02 kB +2.91% 14.43 kB 14.85 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2.17% 60.90 kB 62.23 kB +2.90% 14.49 kB 14.91 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +2.16% 65.31 kB 66.73 kB +3.02% 15.94 kB 16.42 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +2.16% 65.31 kB 66.73 kB +3.02% 15.94 kB 16.42 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.16% 65.35 kB 66.76 kB +3.02% 15.97 kB 16.45 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.16% 65.35 kB 66.76 kB +3.02% 15.97 kB 16.45 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +2.12% 66.75 kB 68.16 kB +2.92% 16.33 kB 16.81 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +2.12% 66.75 kB 68.16 kB +2.92% 16.33 kB 16.81 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.12% 66.77 kB 68.19 kB +2.90% 16.37 kB 16.85 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +2.12% 66.77 kB 68.19 kB +2.90% 16.37 kB 16.85 kB
oss-stable-semver/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +2.09% 67.61 kB 69.03 kB +2.89% 16.53 kB 17.01 kB
oss-stable/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +2.09% 67.61 kB 69.03 kB +2.89% 16.53 kB 17.01 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.09% 67.64 kB 69.05 kB +2.87% 16.57 kB 17.05 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +2.09% 67.64 kB 69.05 kB +2.87% 16.57 kB 17.05 kB
oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +2.06% 68.62 kB 70.03 kB +2.80% 16.40 kB 16.86 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.browser.development.js +2.06% 64.15 kB 65.48 kB +2.79% 15.46 kB 15.89 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.development.js +2.04% 64.66 kB 65.99 kB +2.72% 15.64 kB 16.06 kB
oss-experimental/react-server-dom-turbopack/umd/react-server-dom-turbopack-client.browser.development.js +2.04% 68.18 kB 69.57 kB +2.78% 15.71 kB 16.15 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.development.js +2.02% 68.72 kB 70.11 kB +2.74% 15.89 kB 16.33 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.unbundled.development.js +2.01% 70.40 kB 71.81 kB +2.87% 16.95 kB 17.43 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2.01% 70.43 kB 71.85 kB +2.85% 16.97 kB 17.45 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.node.development.js +1.97% 71.83 kB 73.25 kB +2.75% 17.33 kB 17.81 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js +1.97% 71.86 kB 73.27 kB +2.73% 17.38 kB 17.85 kB
oss-experimental/react-server-dom-turbopack/cjs/react-server-dom-turbopack-client.edge.development.js +1.94% 72.70 kB 74.11 kB +2.72% 17.54 kB 18.02 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.development.js +1.94% 72.73 kB 74.14 kB +2.70% 17.58 kB 18.06 kB
oss-stable-semver/react-client/cjs/react-client-flight.production.min.js +0.20% 10.44 kB 10.46 kB +0.23% 3.90 kB 3.91 kB
oss-stable/react-client/cjs/react-client-flight.production.min.js +0.20% 10.44 kB 10.46 kB +0.23% 3.90 kB 3.91 kB
test_utils/ReactAllWarnings.js Deleted 66.50 kB 0.00 kB Deleted 16.27 kB 0.00 kB

Generated by 🚫 dangerJS against 525b3e5

@gaearon
Copy link
Collaborator

gaearon commented Feb 21, 2024

The badges are sick. 🔥

Comment on lines +30 to +42
case 'dir':
case 'dirxml':
case 'groupEnd':
case 'table': {
// These methods cannot be colorized because they don't take a formatting string.
// eslint-disable-next-line react-internal/no-production-logging
console[methodName].apply(console, args);
return;
}
case 'assert': {
// assert takes formatting options as the second argument.
offset = 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we allowlist these methods somewhere? I wonder what the behaviour will be if some non-standard console methods are called, like console.timeStamp or console.createTask?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we only patch a subset. The list and what was excluded is commented on here:

#28384 (comment)

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.

Reviewed 6 commits at the top, basically what is stacked. Cool stuff.

Chrome + Terminals tend to support color encoding in ANSI SGR format.

Safari + Chrome + Firefox supports CSS styling encoding.

Therefore in browser settings we need to use CSS styling but on servers
we have to use ANSI SGR.

You can ofc use a browser DevTools inspector to inspect a server, however,
in that case it's probably Chrome which supports ANSI SGR too.
On the server we can use a combination of ANSI and CSS. The ANSI
is used in the terminal while the CSS is ignored, the CSS overrides the
ANSI in Chrome inspector.

For ANSI we use the inverted colors (flip foreground/background) instead of
any specific set of colors since we don't know what color scheme is used.

In the browser, we can't use ANSI because Safari and Firefox will print
them in the inspector, but we can use CSS there.
This works a bit better for multi-line logs.

This means we also don't need normalizeConsoleFormat but I keep it
around in case we change our mind or need it for other logs.
In the terminal it prints the CSS and in the inspector it prints the ANSI.

So we just use a plain bracket instead.
@sebmarkbage sebmarkbage merged commit c027406 into facebook:main Feb 21, 2024
36 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 21, 2024
Builds on top of #28384.

This prefixes each log with a badge similar to how we badge built-ins
like "ForwardRef" and "Memo" in the React DevTools. The idea is that we
can add such badges in DevTools for Server Components too to carry on
the consistency.

This puts the "environment" name in the badge which defaults to
"Server". So you know which source it is coming from.

We try to use the same styling as the React DevTools. We use light-dark
mode where available to support the two different color styles, but if
it's not available I use a fixed background so that it's always readable
even in dark mode.

In Terminals, instead of hard coding colors that might not look good
with some themes, I use the ANSI color code to flip
background/foreground colors in that case.

In earlier commits I had it on the end of the line similar to the
DevTools badges but for multiline I found it better to prefix it. We
could try various options tough.

In most cases we can use both ANSI and the `%c` CSS color specifier,
because node will only use ANSI and hide the other. Chrome supports both
but the color overrides ANSI if it comes later (and Chrome doesn't
support color inverting anyway). Safari/Firefox prints the ANSI, so it
can only use CSS colors.

Therefore in browser builds I exclude ANSI.

On the server I support both so if you use Chrome inspector on the
server, you get nice colors on both terminal and in the inspector.

Since Bun uses WebKit inspector and it prints the ANSI we can't safely
emit both there. However, we also can't emit just the color specifier
because then it prints in the terminal.
oven-sh/bun#9021 So we just use a plain string
prefix for now with a bracket until that's fixed.

Screen shots:

<img width="758" alt="Screenshot 2024-02-21 at 12 56 02 AM"
src="https://github.com/facebook/react/assets/63648/4f887ffe-fffe-4402-bf2a-b7890986d60c">
<img width="759" alt="Screenshot 2024-02-21 at 12 56 24 AM"
src="https://github.com/facebook/react/assets/63648/f32d432f-f738-4872-a700-ea0a78e6c745">
<img width="514" alt="Screenshot 2024-02-21 at 12 57 10 AM"
src="https://github.com/facebook/react/assets/63648/205d2e82-75b7-4e2b-9d9c-aa9e2cbedf39">
<img width="489" alt="Screenshot 2024-02-21 at 12 57 34 AM"
src="https://github.com/facebook/react/assets/63648/ea52d1e4-b9fa-431d-ae9e-ccb87631f399">
<img width="516" alt="Screenshot 2024-02-21 at 12 58 23 AM"
src="https://github.com/facebook/react/assets/63648/52b50fac-bec0-471d-a457-1a10d8df9172">
<img width="956" alt="Screenshot 2024-02-21 at 12 58 56 AM"
src="https://github.com/facebook/react/assets/63648/0096ed61-5eff-4aa9-8a8a-2204e754bd1f">

DiffTrain build for [c027406](c027406)
@rickhanlonii
Copy link
Member

This is sick

EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
Builds on top of facebook#28384.

This prefixes each log with a badge similar to how we badge built-ins
like "ForwardRef" and "Memo" in the React DevTools. The idea is that we
can add such badges in DevTools for Server Components too to carry on
the consistency.

This puts the "environment" name in the badge which defaults to
"Server". So you know which source it is coming from.

We try to use the same styling as the React DevTools. We use light-dark
mode where available to support the two different color styles, but if
it's not available I use a fixed background so that it's always readable
even in dark mode.

In Terminals, instead of hard coding colors that might not look good
with some themes, I use the ANSI color code to flip
background/foreground colors in that case.

In earlier commits I had it on the end of the line similar to the
DevTools badges but for multiline I found it better to prefix it. We
could try various options tough.

In most cases we can use both ANSI and the `%c` CSS color specifier,
because node will only use ANSI and hide the other. Chrome supports both
but the color overrides ANSI if it comes later (and Chrome doesn't
support color inverting anyway). Safari/Firefox prints the ANSI, so it
can only use CSS colors.

Therefore in browser builds I exclude ANSI.

On the server I support both so if you use Chrome inspector on the
server, you get nice colors on both terminal and in the inspector.

Since Bun uses WebKit inspector and it prints the ANSI we can't safely
emit both there. However, we also can't emit just the color specifier
because then it prints in the terminal.
oven-sh/bun#9021 So we just use a plain string
prefix for now with a bracket until that's fixed.

Screen shots:

<img width="758" alt="Screenshot 2024-02-21 at 12 56 02 AM"
src="https://github.com/facebook/react/assets/63648/4f887ffe-fffe-4402-bf2a-b7890986d60c">
<img width="759" alt="Screenshot 2024-02-21 at 12 56 24 AM"
src="https://github.com/facebook/react/assets/63648/f32d432f-f738-4872-a700-ea0a78e6c745">
<img width="514" alt="Screenshot 2024-02-21 at 12 57 10 AM"
src="https://github.com/facebook/react/assets/63648/205d2e82-75b7-4e2b-9d9c-aa9e2cbedf39">
<img width="489" alt="Screenshot 2024-02-21 at 12 57 34 AM"
src="https://github.com/facebook/react/assets/63648/ea52d1e4-b9fa-431d-ae9e-ccb87631f399">
<img width="516" alt="Screenshot 2024-02-21 at 12 58 23 AM"
src="https://github.com/facebook/react/assets/63648/52b50fac-bec0-471d-a457-1a10d8df9172">
<img width="956" alt="Screenshot 2024-02-21 at 12 58 56 AM"
src="https://github.com/facebook/react/assets/63648/0096ed61-5eff-4aa9-8a8a-2204e754bd1f">
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
Builds on top of #28384.

This prefixes each log with a badge similar to how we badge built-ins
like "ForwardRef" and "Memo" in the React DevTools. The idea is that we
can add such badges in DevTools for Server Components too to carry on
the consistency.

This puts the "environment" name in the badge which defaults to
"Server". So you know which source it is coming from.

We try to use the same styling as the React DevTools. We use light-dark
mode where available to support the two different color styles, but if
it's not available I use a fixed background so that it's always readable
even in dark mode.

In Terminals, instead of hard coding colors that might not look good
with some themes, I use the ANSI color code to flip
background/foreground colors in that case.

In earlier commits I had it on the end of the line similar to the
DevTools badges but for multiline I found it better to prefix it. We
could try various options tough.

In most cases we can use both ANSI and the `%c` CSS color specifier,
because node will only use ANSI and hide the other. Chrome supports both
but the color overrides ANSI if it comes later (and Chrome doesn't
support color inverting anyway). Safari/Firefox prints the ANSI, so it
can only use CSS colors.

Therefore in browser builds I exclude ANSI.

On the server I support both so if you use Chrome inspector on the
server, you get nice colors on both terminal and in the inspector.

Since Bun uses WebKit inspector and it prints the ANSI we can't safely
emit both there. However, we also can't emit just the color specifier
because then it prints in the terminal.
oven-sh/bun#9021 So we just use a plain string
prefix for now with a bracket until that's fixed.

Screen shots:

<img width="758" alt="Screenshot 2024-02-21 at 12 56 02 AM"
src="https://github.com/facebook/react/assets/63648/4f887ffe-fffe-4402-bf2a-b7890986d60c">
<img width="759" alt="Screenshot 2024-02-21 at 12 56 24 AM"
src="https://github.com/facebook/react/assets/63648/f32d432f-f738-4872-a700-ea0a78e6c745">
<img width="514" alt="Screenshot 2024-02-21 at 12 57 10 AM"
src="https://github.com/facebook/react/assets/63648/205d2e82-75b7-4e2b-9d9c-aa9e2cbedf39">
<img width="489" alt="Screenshot 2024-02-21 at 12 57 34 AM"
src="https://github.com/facebook/react/assets/63648/ea52d1e4-b9fa-431d-ae9e-ccb87631f399">
<img width="516" alt="Screenshot 2024-02-21 at 12 58 23 AM"
src="https://github.com/facebook/react/assets/63648/52b50fac-bec0-471d-a457-1a10d8df9172">
<img width="956" alt="Screenshot 2024-02-21 at 12 58 56 AM"
src="https://github.com/facebook/react/assets/63648/0096ed61-5eff-4aa9-8a8a-2204e754bd1f">

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