-
Notifications
You must be signed in to change notification settings - Fork 47.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DevTools] Implement getComponentStack and onErrorOrWarning for repla…
…yed Flight logs (#30930) This adds owner stacks to replayed Server Component logs in environments that don't support native console.createTask. <img width="521" alt="Screenshot 2024-09-09 at 8 55 21 PM" src="https://github.com/user-attachments/assets/261cfaee-ea65-4044-abf0-c41abf358fea"> It also tracks the logs in the global componentInfoToComponentLogsMap which lets us associate those logs with Server Components when they later commit into the fiber tree. <img width="1280" alt="Screenshot 2024-09-09 at 9 31 16 PM" src="https://github.com/user-attachments/assets/436312a6-f9f4-4add-8129-0fb9b9eb18ee"> I tried to create unit tests for this since it's now wired up end-to-end. Unfortunately, the complicated testing set up for Flight requires a complex set of resetting modules which are incompatible with the complicated test setup in getVersionedRenderImplementation for DevTools tests.
- Loading branch information
1 parent
d160aa0
commit 63cefa2
Showing
3 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/react-devtools-shared/src/backend/flight/DevToolsComponentInfoStack.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,55 @@ | ||
/** | ||
* 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 is a DevTools fork of ReactComponentInfoStack. | ||
// This fork enables DevTools to use the same "native" component stack format, | ||
// while still maintaining support for multiple renderer versions | ||
// (which use different values for ReactTypeOfWork). | ||
|
||
import type {ReactComponentInfo} from 'shared/ReactTypes'; | ||
|
||
import {describeBuiltInComponentFrame} from '../shared/DevToolsComponentStackFrame'; | ||
|
||
import {formatOwnerStack} from '../shared/DevToolsOwnerStack'; | ||
|
||
export function getOwnerStackByComponentInfoInDev( | ||
componentInfo: ReactComponentInfo, | ||
): string { | ||
try { | ||
let info = ''; | ||
|
||
// The owner stack of the current component will be where it was created, i.e. inside its owner. | ||
// There's no actual name of the currently executing component. Instead, that is available | ||
// on the regular stack that's currently executing. However, if there is no owner at all, then | ||
// there's no stack frame so we add the name of the root component to the stack to know which | ||
// component is currently executing. | ||
if (!componentInfo.owner && typeof componentInfo.name === 'string') { | ||
return describeBuiltInComponentFrame(componentInfo.name); | ||
} | ||
|
||
let owner: void | null | ReactComponentInfo = componentInfo; | ||
|
||
while (owner) { | ||
const ownerStack: ?Error = owner.debugStack; | ||
if (ownerStack != null) { | ||
// Server Component | ||
owner = owner.owner; | ||
if (owner) { | ||
// TODO: Should we stash this somewhere for caching purposes? | ||
info += '\n' + formatOwnerStack(ownerStack); | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
return info; | ||
} catch (x) { | ||
return '\nError generating stack: ' + x.message + '\n' + x.stack; | ||
} | ||
} |
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