@@ -813,7 +813,13 @@ function createElement(
813813 console ,
814814 getTaskName ( type ) ,
815815 ) ;
816- const callStack = buildFakeCallStack ( response , stack , env , createTaskFn ) ;
816+ const callStack = buildFakeCallStack (
817+ response ,
818+ stack ,
819+ env ,
820+ false ,
821+ createTaskFn ,
822+ ) ;
817823 // This owner should ideally have already been initialized to avoid getting
818824 // user stack frames on the stack.
819825 const ownerTask =
@@ -2134,6 +2140,7 @@ function resolveErrorDev(
21342140 response ,
21352141 stack ,
21362142 env ,
2143+ false ,
21372144 // $FlowFixMe[incompatible-use]
21382145 Error . bind (
21392146 null ,
@@ -2196,6 +2203,7 @@ function resolvePostponeDev(
21962203 response,
21972204 stack,
21982205 env,
2206+ false,
21992207 // $FlowFixMe[incompatible-use]
22002208 Error.bind(null, reason || ''),
22012209 );
@@ -2404,12 +2412,14 @@ function buildFakeCallStack<T>(
24042412 response: Response,
24052413 stack: ReactStackTrace,
24062414 environmentName: string,
2415+ useEnclosingLine: boolean,
24072416 innerCall: () => T ,
24082417) : ( ) => T {
24092418 let callStack = innerCall ;
24102419 for ( let i = 0 ; i < stack . length ; i ++ ) {
24112420 const frame = stack [ i ] ;
2412- const frameKey = frame . join ( '-' ) + '-' + environmentName ;
2421+ const frameKey =
2422+ frame . join ( '-' ) + '-' + environmentName + '-' + useEnclosingLine ;
24132423 let fn = fakeFunctionCache . get ( frameKey ) ;
24142424 if ( fn === undefined ) {
24152425 const [ name , filename , line , col , enclosingLine , enclosingCol ] = frame ;
@@ -2423,8 +2433,8 @@ function buildFakeCallStack<T>(
24232433 sourceMap ,
24242434 line ,
24252435 col ,
2426- enclosingLine ,
2427- enclosingCol ,
2436+ useEnclosingLine ? line : enclosingLine ,
2437+ useEnclosingLine ? col : enclosingCol ,
24282438 environmentName ,
24292439 ) ;
24302440 // TODO: This cache should technically live on the response since the _debugFindSourceMapURL
@@ -2470,6 +2480,15 @@ function initializeFakeTask(
24702480 // If it's null, we can't initialize a task.
24712481 return null ;
24722482 }
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+
24732492 const stack = debugInfo.stack;
24742493 const env: string =
24752494 debugInfo.env == null ? response._rootEnvironmentName : debugInfo.env;
@@ -2486,6 +2505,7 @@ function initializeFakeTask(
24862505 stack ,
24872506 '"use ' + childEnvironmentName . toLowerCase ( ) + '"' ,
24882507 env ,
2508+ useEnclosingLine ,
24892509 ) ;
24902510 } else {
24912511 const cachedEntry = debugInfo . debugTask ;
@@ -2510,6 +2530,7 @@ function initializeFakeTask(
25102530 stack ,
25112531 taskName ,
25122532 env ,
2533+ useEnclosingLine ,
25132534 ) ) ;
25142535 }
25152536}
@@ -2520,9 +2541,16 @@ function buildFakeTask(
25202541 stack : ReactStackTrace ,
25212542 taskName : string ,
25222543 env : string ,
2544+ useEnclosingLine : boolean ,
25232545) : ConsoleTask {
25242546 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+ ) ;
25262554 if ( ownerTask === null ) {
25272555 const rootTask = getRootTask ( response , env ) ;
25282556 if ( rootTask != null ) {
@@ -2545,6 +2573,7 @@ const createFakeJSXCallStack = {
25452573 response ,
25462574 stack ,
25472575 environmentName ,
2576+ false ,
25482577 fakeJSXCallSite ,
25492578 ) ;
25502579 return callStackForError ( ) ;
@@ -2681,6 +2710,7 @@ const replayConsoleWithCallStack = {
26812710 response ,
26822711 stackTrace ,
26832712 env ,
2713+ false ,
26842714 bindToConsole ( methodName , args , env ) ,
26852715 ) ;
26862716 if ( owner != null ) {
0 commit comments