-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fizz] Implement Component Stacks in DEV for warnings (#21610)
* Implement component stacks This uses a reverse linked list in DEV-only to keep track of where we're currently executing. * Fix bug that wasn't picking up the right stack at suspended boundaries This makes it more explicit which stack we pass in to be retained by the task.
- Loading branch information
1 parent
39f0074
commit 1b7b359
Showing
3 changed files
with
292 additions
and
4 deletions.
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
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,61 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import { | ||
describeBuiltInComponentFrame, | ||
describeFunctionComponentFrame, | ||
describeClassComponentFrame, | ||
} from 'shared/ReactComponentStackFrame'; | ||
|
||
// DEV-only reverse linked list representing the current component stack | ||
type BuiltInComponentStackNode = { | ||
tag: 0, | ||
parent: null | ComponentStackNode, | ||
type: string, | ||
}; | ||
type FunctionComponentStackNode = { | ||
tag: 1, | ||
parent: null | ComponentStackNode, | ||
type: Function, | ||
}; | ||
type ClassComponentStackNode = { | ||
tag: 2, | ||
parent: null | ComponentStackNode, | ||
type: Function, | ||
}; | ||
export type ComponentStackNode = | ||
| BuiltInComponentStackNode | ||
| FunctionComponentStackNode | ||
| ClassComponentStackNode; | ||
|
||
export function getStackByComponentStackNode( | ||
componentStack: ComponentStackNode, | ||
): string { | ||
try { | ||
let info = ''; | ||
let node = componentStack; | ||
do { | ||
switch (node.tag) { | ||
case 0: | ||
info += describeBuiltInComponentFrame(node.type, null, null); | ||
break; | ||
case 1: | ||
info += describeFunctionComponentFrame(node.type, null, null); | ||
break; | ||
case 2: | ||
info += describeClassComponentFrame(node.type, null, null); | ||
break; | ||
} | ||
node = node.parent; | ||
} while (node); | ||
return info; | ||
} catch (x) { | ||
return '\nError generating stack: ' + x.message + '\n' + x.stack; | ||
} | ||
} |
Oops, something went wrong.