@samitouri / QOS-React-2 / commits / f6fb1a07a5

[Flight] Remove superfluous whitespace when console method is called with non-strings (#33953)

Sebastian "Sebbie" Silbermann committed Jul 23, 2025 at 10:07 UTC f6fb1a07a5fda2aa436f6ddf9a31025945cd67b3
6 files changed +27 -12
packages/react-client/src/ReactClientConsoleConfigBrowser.js
+2 -2
@@ -8,7 +8,7 @@
8 */
9
10 // Keep in sync with ReactServerConsoleConfig
11 -const badgeFormat = '%c%s%c ';
11 +const badgeFormat = '%c%s%c';
12 // Same badge styling as DevTools.
13 const badgeStyle =
14 // We use a fixed background if light-dark is not supported, otherwise
@@ -49,7 +49,7 @@ export function bindToConsole(
49 newArgs.splice(
50 offset,
51 1,
52 - badgeFormat + newArgs[offset],
52 + badgeFormat + ' ' + newArgs[offset],
53 badgeStyle,
54 pad + badgeName + pad,
55 resetStyle,
packages/react-client/src/ReactClientConsoleConfigPlain.js
+2 -2
@@ -8,7 +8,7 @@
8 */
9
10 // Keep in sync with ReactServerConsoleConfig
11 -const badgeFormat = '[%s] ';
11 +const badgeFormat = '[%s]';
12 const pad = ' ';
13
14 const bind = Function.prototype.bind;
@@ -39,7 +39,7 @@ export function bindToConsole(
39 newArgs.splice(
40 offset,
41 1,
42 - badgeFormat + newArgs[offset],
42 + badgeFormat + ' ' + newArgs[offset],
43 pad + badgeName + pad,
44 );
45 } else {
packages/react-client/src/ReactClientConsoleConfigServer.js
+2 -2
@@ -9,7 +9,7 @@
9
10 // Keep in sync with ReactServerConsoleConfig
11 // This flips color using ANSI, then sets a color styling, then resets.
12 -const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c ';
12 +const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c';
13 // Same badge styling as DevTools.
14 const badgeStyle =
15 // We use a fixed background if light-dark is not supported, otherwise
@@ -50,7 +50,7 @@ export function bindToConsole(
50 newArgs.splice(
51 offset,
52 1,
53 - badgeFormat + newArgs[offset],
53 + badgeFormat + ' ' + newArgs[offset],
54 badgeStyle,
55 pad + badgeName + pad,
56 resetStyle,
packages/react-server/src/ReactServerConsoleConfigBrowser.js
+7 -2
@@ -8,7 +8,7 @@
8 */
9
10 // Keep in sync with ReactClientConsoleConfig
11 -const badgeFormat = '%c%s%c ';
11 +const badgeFormat = '%c%s%c';
12 // Same badge styling as DevTools.
13 const badgeStyle =
14 // We use a fixed background if light-dark is not supported, otherwise
@@ -54,7 +54,12 @@ export function unbadgeConsole(
54 typeof badge === 'string'
55 ) {
56 // Remove our badging from the arguments.
57 - args.splice(offset, 4, format.slice(badgeFormat.length));
57 + let unbadgedFormat = format.slice(badgeFormat.length);
58 + if (unbadgedFormat[0] === ' ') {
59 + // Spacing added on the Client if the original argument was a string.
60 + unbadgedFormat = unbadgedFormat.slice(1);
61 + }
62 + args.splice(offset, 4, unbadgedFormat);
63 return badge.slice(padLength, badge.length - padLength);
64 }
65 return null;
packages/react-server/src/ReactServerConsoleConfigPlain.js
+7 -2
@@ -8,7 +8,7 @@
8 */
9
10 // Keep in sync with ReactClientConsoleConfig
11 -const badgeFormat = '[%s] ';
11 +const badgeFormat = '[%s]';
12 const padLength = 1;
13 const pad = ' ';
14
@@ -45,7 +45,12 @@ export function unbadgeConsole(
45 badge.endsWith(pad)
46 ) {
47 // Remove our badging from the arguments.
48 - args.splice(offset, 2, format.slice(badgeFormat.length));
48 + let unbadgedFormat = format.slice(badgeFormat.length);
49 + if (unbadgedFormat[0] === ' ') {
50 + // Spacing added on the Client if the original argument was a string.
51 + unbadgedFormat = unbadgedFormat.slice(1);
52 + }
53 + args.splice(offset, 4, unbadgedFormat);
54 return badge.slice(padLength, badge.length - padLength);
55 }
56 return null;
packages/react-server/src/ReactServerConsoleConfigServer.js
+7 -2
@@ -8,7 +8,7 @@
8 */
9
10 // Keep in sync with ReactClientConsoleConfig
11 -const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c ';
11 +const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c';
12 // Same badge styling as DevTools.
13 const badgeStyle =
14 // We use a fixed background if light-dark is not supported, otherwise
@@ -53,7 +53,12 @@ export function unbadgeConsole(
53 typeof badge === 'string'
54 ) {
55 // Remove our badging from the arguments.
56 - args.splice(offset, 4, format.slice(badgeFormat.length));
56 + let unbadgedFormat = format.slice(badgeFormat.length);
57 + if (unbadgedFormat[0] === ' ') {
58 + // Spacing added on the Client if the original argument was a string.
59 + unbadgedFormat = unbadgedFormat.slice(1);
60 + }
61 + args.splice(offset, 4, unbadgedFormat);
62 return badge.slice(padLength, badge.length - padLength);
63 }
64 return null;