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

This commit is contained in:
Sebastian "Sebbie" Silbermann 2025-07-23 10:07:37 +02:00 committed by GitHub
parent 7513996f20
commit f6fb1a07a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 12 deletions

View File

@ -8,7 +8,7 @@
*/ */
// Keep in sync with ReactServerConsoleConfig // Keep in sync with ReactServerConsoleConfig
const badgeFormat = '%c%s%c '; const badgeFormat = '%c%s%c';
// Same badge styling as DevTools. // Same badge styling as DevTools.
const badgeStyle = const badgeStyle =
// We use a fixed background if light-dark is not supported, otherwise // We use a fixed background if light-dark is not supported, otherwise
@ -49,7 +49,7 @@ export function bindToConsole(
newArgs.splice( newArgs.splice(
offset, offset,
1, 1,
badgeFormat + newArgs[offset], badgeFormat + ' ' + newArgs[offset],
badgeStyle, badgeStyle,
pad + badgeName + pad, pad + badgeName + pad,
resetStyle, resetStyle,

View File

@ -8,7 +8,7 @@
*/ */
// Keep in sync with ReactServerConsoleConfig // Keep in sync with ReactServerConsoleConfig
const badgeFormat = '[%s] '; const badgeFormat = '[%s]';
const pad = ' '; const pad = ' ';
const bind = Function.prototype.bind; const bind = Function.prototype.bind;
@ -39,7 +39,7 @@ export function bindToConsole(
newArgs.splice( newArgs.splice(
offset, offset,
1, 1,
badgeFormat + newArgs[offset], badgeFormat + ' ' + newArgs[offset],
pad + badgeName + pad, pad + badgeName + pad,
); );
} else { } else {

View File

@ -9,7 +9,7 @@
// Keep in sync with ReactServerConsoleConfig // Keep in sync with ReactServerConsoleConfig
// This flips color using ANSI, then sets a color styling, then resets. // This flips color using ANSI, then sets a color styling, then resets.
const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c '; const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c';
// Same badge styling as DevTools. // Same badge styling as DevTools.
const badgeStyle = const badgeStyle =
// We use a fixed background if light-dark is not supported, otherwise // We use a fixed background if light-dark is not supported, otherwise
@ -50,7 +50,7 @@ export function bindToConsole(
newArgs.splice( newArgs.splice(
offset, offset,
1, 1,
badgeFormat + newArgs[offset], badgeFormat + ' ' + newArgs[offset],
badgeStyle, badgeStyle,
pad + badgeName + pad, pad + badgeName + pad,
resetStyle, resetStyle,

View File

@ -8,7 +8,7 @@
*/ */
// Keep in sync with ReactClientConsoleConfig // Keep in sync with ReactClientConsoleConfig
const badgeFormat = '%c%s%c '; const badgeFormat = '%c%s%c';
// Same badge styling as DevTools. // Same badge styling as DevTools.
const badgeStyle = const badgeStyle =
// We use a fixed background if light-dark is not supported, otherwise // We use a fixed background if light-dark is not supported, otherwise
@ -54,7 +54,12 @@ export function unbadgeConsole(
typeof badge === 'string' typeof badge === 'string'
) { ) {
// Remove our badging from the arguments. // Remove our badging from the arguments.
args.splice(offset, 4, format.slice(badgeFormat.length)); let unbadgedFormat = format.slice(badgeFormat.length);
if (unbadgedFormat[0] === ' ') {
// Spacing added on the Client if the original argument was a string.
unbadgedFormat = unbadgedFormat.slice(1);
}
args.splice(offset, 4, unbadgedFormat);
return badge.slice(padLength, badge.length - padLength); return badge.slice(padLength, badge.length - padLength);
} }
return null; return null;

View File

@ -8,7 +8,7 @@
*/ */
// Keep in sync with ReactClientConsoleConfig // Keep in sync with ReactClientConsoleConfig
const badgeFormat = '[%s] '; const badgeFormat = '[%s]';
const padLength = 1; const padLength = 1;
const pad = ' '; const pad = ' ';
@ -45,7 +45,12 @@ export function unbadgeConsole(
badge.endsWith(pad) badge.endsWith(pad)
) { ) {
// Remove our badging from the arguments. // Remove our badging from the arguments.
args.splice(offset, 2, format.slice(badgeFormat.length)); let unbadgedFormat = format.slice(badgeFormat.length);
if (unbadgedFormat[0] === ' ') {
// Spacing added on the Client if the original argument was a string.
unbadgedFormat = unbadgedFormat.slice(1);
}
args.splice(offset, 4, unbadgedFormat);
return badge.slice(padLength, badge.length - padLength); return badge.slice(padLength, badge.length - padLength);
} }
return null; return null;

View File

@ -8,7 +8,7 @@
*/ */
// Keep in sync with ReactClientConsoleConfig // Keep in sync with ReactClientConsoleConfig
const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c '; const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c';
// Same badge styling as DevTools. // Same badge styling as DevTools.
const badgeStyle = const badgeStyle =
// We use a fixed background if light-dark is not supported, otherwise // We use a fixed background if light-dark is not supported, otherwise
@ -53,7 +53,12 @@ export function unbadgeConsole(
typeof badge === 'string' typeof badge === 'string'
) { ) {
// Remove our badging from the arguments. // Remove our badging from the arguments.
args.splice(offset, 4, format.slice(badgeFormat.length)); let unbadgedFormat = format.slice(badgeFormat.length);
if (unbadgedFormat[0] === ' ') {
// Spacing added on the Client if the original argument was a string.
unbadgedFormat = unbadgedFormat.slice(1);
}
args.splice(offset, 4, unbadgedFormat);
return badge.slice(padLength, badge.length - padLength); return badge.slice(padLength, badge.length - padLength);
} }
return null; return null;