Skip to content

Commit f6fb1a0

Browse files
authored
[Flight] Remove superfluous whitespace when console method is called with non-strings (facebook#33953)
1 parent 7513996 commit f6fb1a0

6 files changed

+27
-12
lines changed

packages/react-client/src/ReactClientConsoleConfigBrowser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// Keep in sync with ReactServerConsoleConfig
11-
const badgeFormat = '%c%s%c ';
11+
const badgeFormat = '%c%s%c';
1212
// Same badge styling as DevTools.
1313
const badgeStyle =
1414
// We use a fixed background if light-dark is not supported, otherwise
@@ -49,7 +49,7 @@ export function bindToConsole(
4949
newArgs.splice(
5050
offset,
5151
1,
52-
badgeFormat + newArgs[offset],
52+
badgeFormat + ' ' + newArgs[offset],
5353
badgeStyle,
5454
pad + badgeName + pad,
5555
resetStyle,

packages/react-client/src/ReactClientConsoleConfigPlain.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// Keep in sync with ReactServerConsoleConfig
11-
const badgeFormat = '[%s] ';
11+
const badgeFormat = '[%s]';
1212
const pad = ' ';
1313

1414
const bind = Function.prototype.bind;
@@ -39,7 +39,7 @@ export function bindToConsole(
3939
newArgs.splice(
4040
offset,
4141
1,
42-
badgeFormat + newArgs[offset],
42+
badgeFormat + ' ' + newArgs[offset],
4343
pad + badgeName + pad,
4444
);
4545
} else {

packages/react-client/src/ReactClientConsoleConfigServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// Keep in sync with ReactServerConsoleConfig
1111
// 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';
1313
// Same badge styling as DevTools.
1414
const badgeStyle =
1515
// We use a fixed background if light-dark is not supported, otherwise
@@ -50,7 +50,7 @@ export function bindToConsole(
5050
newArgs.splice(
5151
offset,
5252
1,
53-
badgeFormat + newArgs[offset],
53+
badgeFormat + ' ' + newArgs[offset],
5454
badgeStyle,
5555
pad + badgeName + pad,
5656
resetStyle,

packages/react-server/src/ReactServerConsoleConfigBrowser.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// Keep in sync with ReactClientConsoleConfig
11-
const badgeFormat = '%c%s%c ';
11+
const badgeFormat = '%c%s%c';
1212
// Same badge styling as DevTools.
1313
const badgeStyle =
1414
// We use a fixed background if light-dark is not supported, otherwise
@@ -54,7 +54,12 @@ export function unbadgeConsole(
5454
typeof badge === 'string'
5555
) {
5656
// 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);
5863
return badge.slice(padLength, badge.length - padLength);
5964
}
6065
return null;

packages/react-server/src/ReactServerConsoleConfigPlain.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// Keep in sync with ReactClientConsoleConfig
11-
const badgeFormat = '[%s] ';
11+
const badgeFormat = '[%s]';
1212
const padLength = 1;
1313
const pad = ' ';
1414

@@ -45,7 +45,12 @@ export function unbadgeConsole(
4545
badge.endsWith(pad)
4646
) {
4747
// 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);
4954
return badge.slice(padLength, badge.length - padLength);
5055
}
5156
return null;

packages/react-server/src/ReactServerConsoleConfigServer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// 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';
1212
// Same badge styling as DevTools.
1313
const badgeStyle =
1414
// We use a fixed background if light-dark is not supported, otherwise
@@ -53,7 +53,12 @@ export function unbadgeConsole(
5353
typeof badge === 'string'
5454
) {
5555
// 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);
5762
return badge.slice(padLength, badge.length - padLength);
5863
}
5964
return null;

0 commit comments

Comments
 (0)