@@ -813,7 +813,13 @@ function createElement(
813
813
console ,
814
814
getTaskName ( type ) ,
815
815
) ;
816
- const callStack = buildFakeCallStack ( response , stack , env , createTaskFn ) ;
816
+ const callStack = buildFakeCallStack (
817
+ response ,
818
+ stack ,
819
+ env ,
820
+ false ,
821
+ createTaskFn ,
822
+ ) ;
817
823
// This owner should ideally have already been initialized to avoid getting
818
824
// user stack frames on the stack.
819
825
const ownerTask =
@@ -2134,6 +2140,7 @@ function resolveErrorDev(
2134
2140
response ,
2135
2141
stack ,
2136
2142
env ,
2143
+ false ,
2137
2144
// $FlowFixMe[incompatible-use]
2138
2145
Error . bind (
2139
2146
null ,
@@ -2196,6 +2203,7 @@ function resolvePostponeDev(
2196
2203
response,
2197
2204
stack,
2198
2205
env,
2206
+ false,
2199
2207
// $FlowFixMe[incompatible-use]
2200
2208
Error.bind(null, reason || ''),
2201
2209
);
@@ -2404,12 +2412,14 @@ function buildFakeCallStack<T>(
2404
2412
response: Response,
2405
2413
stack: ReactStackTrace,
2406
2414
environmentName: string,
2415
+ useEnclosingLine: boolean,
2407
2416
innerCall: () => T ,
2408
2417
) : ( ) => T {
2409
2418
let callStack = innerCall ;
2410
2419
for ( let i = 0 ; i < stack . length ; i ++ ) {
2411
2420
const frame = stack [ i ] ;
2412
- const frameKey = frame . join ( '-' ) + '-' + environmentName ;
2421
+ const frameKey =
2422
+ frame . join ( '-' ) + '-' + environmentName + '-' + useEnclosingLine ;
2413
2423
let fn = fakeFunctionCache . get ( frameKey ) ;
2414
2424
if ( fn === undefined ) {
2415
2425
const [ name , filename , line , col , enclosingLine , enclosingCol ] = frame ;
@@ -2423,8 +2433,8 @@ function buildFakeCallStack<T>(
2423
2433
sourceMap ,
2424
2434
line ,
2425
2435
col ,
2426
- enclosingLine ,
2427
- enclosingCol ,
2436
+ useEnclosingLine ? line : enclosingLine ,
2437
+ useEnclosingLine ? col : enclosingCol ,
2428
2438
environmentName ,
2429
2439
) ;
2430
2440
// TODO: This cache should technically live on the response since the _debugFindSourceMapURL
@@ -2470,6 +2480,15 @@ function initializeFakeTask(
2470
2480
// If it's null, we can't initialize a task.
2471
2481
return null ;
2472
2482
}
2483
+
2484
+ // Workaround for a bug where Chrome Performance tracking uses the enclosing line/column
2485
+ // instead of the callsite. For ReactAsyncInfo/ReactIOInfo, the only thing we're going
2486
+ // to use the fake task for is the Performance tracking so we encode the enclosing line/
2487
+ // column at the callsite to get a better line number. We could do this for Components too
2488
+ // but we're going to use those for other things too like console logs and it's not worth
2489
+ // duplicating. If this bug is every fixed in Chrome, this should be set to false.
2490
+ const useEnclosingLine = debugInfo.key === undefined;
2491
+
2473
2492
const stack = debugInfo.stack;
2474
2493
const env: string =
2475
2494
debugInfo.env == null ? response._rootEnvironmentName : debugInfo.env;
@@ -2486,6 +2505,7 @@ function initializeFakeTask(
2486
2505
stack ,
2487
2506
'"use ' + childEnvironmentName . toLowerCase ( ) + '"' ,
2488
2507
env ,
2508
+ useEnclosingLine ,
2489
2509
) ;
2490
2510
} else {
2491
2511
const cachedEntry = debugInfo . debugTask ;
@@ -2510,6 +2530,7 @@ function initializeFakeTask(
2510
2530
stack ,
2511
2531
taskName ,
2512
2532
env ,
2533
+ useEnclosingLine ,
2513
2534
) ) ;
2514
2535
}
2515
2536
}
@@ -2520,9 +2541,16 @@ function buildFakeTask(
2520
2541
stack : ReactStackTrace ,
2521
2542
taskName : string ,
2522
2543
env : string ,
2544
+ useEnclosingLine : boolean ,
2523
2545
) : ConsoleTask {
2524
2546
const createTaskFn = ( console : any ) . createTask . bind ( console , taskName ) ;
2525
- const callStack = buildFakeCallStack ( response , stack , env , createTaskFn ) ;
2547
+ const callStack = buildFakeCallStack (
2548
+ response ,
2549
+ stack ,
2550
+ env ,
2551
+ useEnclosingLine ,
2552
+ createTaskFn ,
2553
+ ) ;
2526
2554
if ( ownerTask === null ) {
2527
2555
const rootTask = getRootTask ( response , env ) ;
2528
2556
if ( rootTask != null ) {
@@ -2545,6 +2573,7 @@ const createFakeJSXCallStack = {
2545
2573
response ,
2546
2574
stack ,
2547
2575
environmentName ,
2576
+ false ,
2548
2577
fakeJSXCallSite ,
2549
2578
) ;
2550
2579
return callStackForError ( ) ;
@@ -2681,6 +2710,7 @@ const replayConsoleWithCallStack = {
2681
2710
response ,
2682
2711
stackTrace ,
2683
2712
env ,
2713
+ false ,
2684
2714
bindToConsole ( methodName , args , env ) ,
2685
2715
) ;
2686
2716
if ( owner != null ) {
0 commit comments