844
// This owner should ideally have already been initialized to avoid getting
845
// user stack frames on the stack.
846
const ownerTask =
847
- owner === null ? null : initializeFakeTask(response, owner, env);
847
+ owner === null ? null : initializeFakeTask(response, owner);
848
if (ownerTask === null) {
849
const rootTask = response._debugRootTask;
850
if (rootTask != null) {
2494
function initializeFakeTask(
2495
response: Response,
2496
debugInfo: ReactComponentInfo | ReactAsyncInfo | ReactIOInfo,
2497
- childEnvironmentName: string,
2497
): null | ConsoleTask {
2498
if (!supportsCreateTask) {
2499
return null;
2503
// If it's null, we can't initialize a task.
2504
return null;
2505
}
2506
+ const cachedEntry = debugInfo.debugTask;
2507
+ if (cachedEntry !== undefined) {
2508
+ return cachedEntry;
2509
+ }
2510
2511
// Workaround for a bug where Chrome Performance tracking uses the enclosing line/column
2512
// instead of the callsite. For ReactAsyncInfo/ReactIOInfo, the only thing we're going
2519
const stack = debugInfo.stack;
2520
const env: string =
2521
debugInfo.env == null ? response._rootEnvironmentName : debugInfo.env;
2519
- if (env !== childEnvironmentName) {
2522
+ const ownerEnv: string =
2523
+ debugInfo.owner == null || debugInfo.owner.env == null
2524
+ ? response._rootEnvironmentName
2525
+ : debugInfo.owner.env;
2526
+ const ownerTask =
2527
+ debugInfo.owner == null
2528
+ ? null
2529
+ : initializeFakeTask(response, debugInfo.owner);
2530
+ const taskName =
2531
// This is the boundary between two environments so we'll annotate the task name.
2521
- // That is unusual so we don't cache it.
2522
- const ownerTask =
2523
- debugInfo.owner == null
2524
- ? null
2525
- : initializeFakeTask(response, debugInfo.owner, env);
2526
- return buildFakeTask(
2527
- response,
2528
- ownerTask,
2529
- stack,
2530
- '"use ' + childEnvironmentName.toLowerCase() + '"',
2531
- env,
2532
- useEnclosingLine,
2533
- );
2534
- } else {
2535
- const cachedEntry = debugInfo.debugTask;
2536
- if (cachedEntry !== undefined) {
2537
- return cachedEntry;
2538
- }
2539
- const ownerTask =
2540
- debugInfo.owner == null
2541
- ? null
2542
- : initializeFakeTask(response, debugInfo.owner, env);
2543
- // Some unfortunate pattern matching to refine the type.
2544
- const taskName =
2545
- debugInfo.key !== undefined
2532
+ // We assume that the stack frame of the entry into the new environment was done
2533
+ // from the old environment. So we use the owner's environment as the current.
2534
+ env !== ownerEnv
2535
+ ? '"use ' + env.toLowerCase() + '"'
2536
+ : // Some unfortunate pattern matching to refine the type.
2537
+ debugInfo.key !== undefined
2538
? getServerComponentTaskName(((debugInfo: any): ReactComponentInfo))
2539
: debugInfo.name !== undefined
2540
? getIOInfoTaskName(((debugInfo: any): ReactIOInfo))
2541
: getAsyncInfoTaskName(((debugInfo: any): ReactAsyncInfo));
2550
- // $FlowFixMe[cannot-write]: We consider this part of initialization.
2551
- return (debugInfo.debugTask = buildFakeTask(
2552
- response,
2553
- ownerTask,
2554
- stack,
2555
- taskName,
2556
- env,
2557
- useEnclosingLine,
2558
- ));
2559
- }
2542
+ // $FlowFixMe[cannot-write]: We consider this part of initialization.
2543
+ return (debugInfo.debugTask = buildFakeTask(
2544
+ response,
2545
+ ownerTask,
2546
+ stack,
2547
+ taskName,
2548
+ ownerEnv,
2549
+ useEnclosingLine,
2550
+ ));
2551
}
2552
2553
function buildFakeTask(
2649
'resolveDebugInfo should never be called in production mode. This is a bug in React.',
2650
);
2651
}
2661
- // We eagerly initialize the fake task because this resolving happens outside any
2662
- // render phase so we're not inside a user space stack at this point. If we waited
2663
- // to initialize it when we need it, we might be inside user code.
2664
- const env =
2665
- debugInfo.env === undefined ? response._rootEnvironmentName : debugInfo.env;
2652
if (debugInfo.stack !== undefined) {
2653
const componentInfoOrAsyncInfo: ReactComponentInfo | ReactAsyncInfo =
2654
// $FlowFixMe[incompatible-type]
2655
debugInfo;
2670
- initializeFakeTask(response, componentInfoOrAsyncInfo, env);
2656
+ // We eagerly initialize the fake task because this resolving happens outside any
2657
+ // render phase so we're not inside a user space stack at this point. If we waited
2658
+ // to initialize it when we need it, we might be inside user code.
2659
+ initializeFakeTask(response, componentInfoOrAsyncInfo);
2660
}
2672
- if (debugInfo.owner === null && response._debugRootOwner != null) {
2661
+ if (debugInfo.owner == null && response._debugRootOwner != null) {
2662
const componentInfoOrAsyncInfo: ReactComponentInfo | ReactAsyncInfo =
2663
// $FlowFixMe: By narrowing `owner` to `null`, we narrowed `debugInfo` to `ReactComponentInfo`
2664
debugInfo;
2665
// $FlowFixMe[cannot-write]
2666
componentInfoOrAsyncInfo.owner = response._debugRootOwner;
2667
+ // We clear the parsed stack frames to indicate that it needs to be re-parsed from debugStack.
2668
+ // $FlowFixMe[cannot-write]
2669
+ componentInfoOrAsyncInfo.stack = null;
2670
// We override the stack if we override the owner since the stack where the root JSX
2671
// was created on the server isn't very useful but where the request was made is.
2672
// $FlowFixMe[cannot-write]
2673
componentInfoOrAsyncInfo.debugStack = response._debugRootStack;
2674
+ // $FlowFixMe[cannot-write]
2675
+ componentInfoOrAsyncInfo.debugTask = response._debugRootTask;
2676
} else if (debugInfo.stack !== undefined) {
2677
const componentInfoOrAsyncInfo: ReactComponentInfo | ReactAsyncInfo =
2678
// $FlowFixMe[incompatible-type]
2732
bindToConsole(methodName, args, env),
2733
);
2734
if (owner != null) {
2741
- const task = initializeFakeTask(response, owner, env);
2735
+ const task = initializeFakeTask(response, owner);
2736
initializeFakeStack(response, owner);
2737
if (task !== null) {
2738
task.run(callStack);
2806
}
2807
2808
function initializeIOInfo(response: Response, ioInfo: ReactIOInfo): void {
2815
- const env =
2816
- ioInfo.env === undefined ? response._rootEnvironmentName : ioInfo.env;
2809
if (ioInfo.stack !== undefined) {
2818
- initializeFakeTask(response, ioInfo, env);
2810
+ initializeFakeTask(response, ioInfo);
2811
initializeFakeStack(response, ioInfo);
2812
}
2813
// Adjust the time to the current environment's time space.