Files
react/packages/react-reconciler/src/ReactFiberComponentStack.js
T
Sebastian Markbåge 72d00ab623 Fix Component Stacks for IE and Native Classes in Safari (#18575)
* Add more edge cases to fixture

Also adjust some expectations. I think the column should ideally be 1 but varies.
The Example row is one line off because it throws on the hook but should ideally be the component.
Similarly class components with constructors may have the line in the constructor.

* Account for the construct call taking a stack frame

We do this by first searching for the first different frame, then find
the same frames and then find the first different frame again.

* Throw controls

Otherwise they don't get a stack frame associated with them in IE.

* Protect against generating stacks failing

Errors while generating stacks will bubble to the root. Since this technique
is a bit sketchy, we should probably protect against it.

* Don't construct the thing that throws

Instead, we pass the prototype as the "this". It's new every time anyway.
2020-04-10 19:39:02 -07:00

74 lines
2.0 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 type {Fiber} from './ReactInternalTypes';
import {
HostComponent,
LazyComponent,
SuspenseComponent,
SuspenseListComponent,
FunctionComponent,
IndeterminateComponent,
ForwardRef,
SimpleMemoComponent,
Block,
ClassComponent,
} from './ReactWorkTags';
import {
describeBuiltInComponentFrame,
describeFunctionComponentFrame,
describeClassComponentFrame,
} from 'shared/ReactComponentStackFrame';
function describeFiber(fiber: Fiber): string {
const owner: null | Function = __DEV__
? fiber._debugOwner
? fiber._debugOwner.type
: null
: null;
const source = __DEV__ ? fiber._debugSource : null;
switch (fiber.tag) {
case HostComponent:
return describeBuiltInComponentFrame(fiber.type, source, owner);
case LazyComponent:
return describeBuiltInComponentFrame('Lazy', source, owner);
case SuspenseComponent:
return describeBuiltInComponentFrame('Suspense', source, owner);
case SuspenseListComponent:
return describeBuiltInComponentFrame('SuspenseList', source, owner);
case FunctionComponent:
case IndeterminateComponent:
case SimpleMemoComponent:
return describeFunctionComponentFrame(fiber.type, source, owner);
case ForwardRef:
return describeFunctionComponentFrame(fiber.type.render, source, owner);
case Block:
return describeFunctionComponentFrame(fiber.type._render, source, owner);
case ClassComponent:
return describeClassComponentFrame(fiber.type, source, owner);
default:
return '';
}
}
export function getStackByFiberInDevAndProd(workInProgress: Fiber): string {
try {
let info = '';
let node = workInProgress;
do {
info += describeFiber(node);
node = node.return;
} while (node);
return info;
} catch (x) {
return '\nError generating stack: ' + x.message + '\n' + x.stack;
}
}