mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
1b7b3592f4
* 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.
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
/**
|
|
* 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;
|
|
}
|
|
}
|