@@ -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,17 @@ 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 ( '-' ) +
2423
+ '-' +
2424
+ environmentName +
2425
+ ( useEnclosingLine ? '-e' : '-n' ) ;
2413
2426
let fn = fakeFunctionCache . get ( frameKey ) ;
2414
2427
if ( fn === undefined ) {
2415
2428
const [ name , filename , line , col , enclosingLine , enclosingCol ] = frame ;
@@ -2423,8 +2436,8 @@ function buildFakeCallStack<T>(
2423
2436
sourceMap ,
2424
2437
line ,
2425
2438
col ,
2426
- enclosingLine ,
2427
- enclosingCol ,
2439
+ useEnclosingLine ? line : enclosingLine ,
2440
+ useEnclosingLine ? col : enclosingCol ,
2428
2441
environmentName ,
2429
2442
) ;
2430
2443
// TODO: This cache should technically live on the response since the _debugFindSourceMapURL
@@ -2470,6 +2483,15 @@ function initializeFakeTask(
2470
2483
// If it's null, we can't initialize a task.
2471
2484
return null ;
2472
2485
}
2486
+
2487
+ // Workaround for a bug where Chrome Performance tracking uses the enclosing line/column
2488
+ // instead of the callsite. For ReactAsyncInfo/ReactIOInfo, the only thing we're going
2489
+ // to use the fake task for is the Performance tracking so we encode the enclosing line/
2490
+ // column at the callsite to get a better line number. We could do this for Components too
2491
+ // but we're going to use those for other things too like console logs and it's not worth
2492
+ // duplicating. If this bug is every fixed in Chrome, this should be set to false.
2493
+ const useEnclosingLine = debugInfo.key === undefined;
2494
+
2473
2495
const stack = debugInfo.stack;
2474
2496
const env: string =
2475
2497
debugInfo.env == null ? response._rootEnvironmentName : debugInfo.env;
@@ -2486,6 +2508,7 @@ function initializeFakeTask(
2486
2508
stack ,
2487
2509
'"use ' + childEnvironmentName . toLowerCase ( ) + '"' ,
2488
2510
env ,
2511
+ useEnclosingLine ,
2489
2512
) ;
2490
2513
} else {
2491
2514
const cachedEntry = debugInfo . debugTask ;
@@ -2510,6 +2533,7 @@ function initializeFakeTask(
2510
2533
stack ,
2511
2534
taskName ,
2512
2535
env ,
2536
+ useEnclosingLine ,
2513
2537
) ) ;
2514
2538
}
2515
2539
}
@@ -2520,9 +2544,16 @@ function buildFakeTask(
2520
2544
stack : ReactStackTrace ,
2521
2545
taskName : string ,
2522
2546
env : string ,
2547
+ useEnclosingLine : boolean ,
2523
2548
) : ConsoleTask {
2524
2549
const createTaskFn = ( console : any ) . createTask . bind ( console , taskName ) ;
2525
- const callStack = buildFakeCallStack ( response , stack , env , createTaskFn ) ;
2550
+ const callStack = buildFakeCallStack (
2551
+ response ,
2552
+ stack ,
2553
+ env ,
2554
+ useEnclosingLine ,
2555
+ createTaskFn ,
2556
+ ) ;
2526
2557
if ( ownerTask === null ) {
2527
2558
const rootTask = getRootTask ( response , env ) ;
2528
2559
if ( rootTask != null ) {
@@ -2545,6 +2576,7 @@ const createFakeJSXCallStack = {
2545
2576
response ,
2546
2577
stack ,
2547
2578
environmentName ,
2579
+ false ,
2548
2580
fakeJSXCallSite ,
2549
2581
) ;
2550
2582
return callStackForError ( ) ;
@@ -2681,6 +2713,7 @@ const replayConsoleWithCallStack = {
2681
2713
response ,
2682
2714
stackTrace ,
2683
2715
env ,
2716
+ false ,
2684
2717
bindToConsole ( methodName , args , env ) ,
2685
2718
) ;
2686
2719
if ( owner != null ) {
0 commit comments