-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b77f6a5
Add console writing forked behavior between server and client
sebmarkbage a48667d
Pass environmentName through to the logs
sebmarkbage 506a075
normalizeConsoleFormat helper
sebmarkbage 96be966
Badge replayed logs by the environment name
sebmarkbage 042bcb9
Move badge to the beginning of the line
sebmarkbage 525b3e5
Bun doesn't currently doesn't support consistent coloring
sebmarkbage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/react-client/src/ReactFlightClientConsoleConfigBrowser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
const badgeFormat = '%c%s%c '; | ||
// Same badge styling as DevTools. | ||
const badgeStyle = | ||
// We use a fixed background if light-dark is not supported, otherwise | ||
// we use a transparent background. | ||
'background: #e6e6e6;' + | ||
'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' + | ||
'color: #000000;' + | ||
'color: light-dark(#000000, #ffffff);' + | ||
'border-radius: 2px'; | ||
const resetStyle = ''; | ||
const pad = ' '; | ||
|
||
export function printToConsole( | ||
methodName: string, | ||
args: Array<any>, | ||
badgeName: string, | ||
): void { | ||
let offset = 0; | ||
switch (methodName) { | ||
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; | ||
} | ||
} | ||
|
||
const newArgs = args.slice(0); | ||
if (typeof newArgs[offset] === 'string') { | ||
newArgs.splice( | ||
offset, | ||
1, | ||
badgeFormat + newArgs[offset], | ||
badgeStyle, | ||
pad + badgeName + pad, | ||
resetStyle, | ||
); | ||
} else { | ||
newArgs.splice( | ||
offset, | ||
0, | ||
badgeFormat, | ||
badgeStyle, | ||
pad + badgeName + pad, | ||
resetStyle, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line react-internal/no-production-logging | ||
console[methodName].apply(console, newArgs); | ||
return; | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/react-client/src/ReactFlightClientConsoleConfigPlain.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
const badgeFormat = '[%s] '; | ||
const pad = ' '; | ||
|
||
export function printToConsole( | ||
methodName: string, | ||
args: Array<any>, | ||
badgeName: string, | ||
): void { | ||
let offset = 0; | ||
switch (methodName) { | ||
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; | ||
} | ||
} | ||
|
||
const newArgs = args.slice(0); | ||
if (typeof newArgs[offset] === 'string') { | ||
newArgs.splice( | ||
offset, | ||
1, | ||
badgeFormat + newArgs[offset], | ||
pad + badgeName + pad, | ||
); | ||
} else { | ||
newArgs.splice(offset, 0, badgeFormat, pad + badgeName + pad); | ||
} | ||
|
||
// eslint-disable-next-line react-internal/no-production-logging | ||
console[methodName].apply(console, newArgs); | ||
return; | ||
} |
70 changes: 70 additions & 0 deletions
70
packages/react-client/src/ReactFlightClientConsoleConfigServer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
// This flips color using ANSI, then sets a color styling, then resets. | ||
const badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c '; | ||
// Same badge styling as DevTools. | ||
const badgeStyle = | ||
// We use a fixed background if light-dark is not supported, otherwise | ||
// we use a transparent background. | ||
'background: #e6e6e6;' + | ||
'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' + | ||
'color: #000000;' + | ||
'color: light-dark(#000000, #ffffff);' + | ||
'border-radius: 2px'; | ||
const resetStyle = ''; | ||
const pad = ' '; | ||
|
||
export function printToConsole( | ||
methodName: string, | ||
args: Array<any>, | ||
badgeName: string, | ||
): void { | ||
let offset = 0; | ||
switch (methodName) { | ||
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; | ||
} | ||
} | ||
|
||
const newArgs = args.slice(0); | ||
if (typeof newArgs[offset] === 'string') { | ||
newArgs.splice( | ||
offset, | ||
1, | ||
badgeFormat + newArgs[offset], | ||
badgeStyle, | ||
pad + badgeName + pad, | ||
resetStyle, | ||
); | ||
} else { | ||
newArgs.splice( | ||
offset, | ||
0, | ||
badgeFormat, | ||
badgeStyle, | ||
pad + badgeName + pad, | ||
resetStyle, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line react-internal/no-production-logging | ||
console[methodName].apply(console, newArgs); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
orconsole.createTask
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I found the answer - https://github.com/facebook/react/pull/28384/files#r1495197550
There was a problem hiding this comment.
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)