@@ -146,7 +146,6 @@ export const defaultThreadViewOptions: ThreadViewOptions = {
146146 expandedInvertedCallNodePaths : new PathSet ( ) ,
147147 expandedLowerWingCallNodePaths : new PathSet ( ) ,
148148 expandedUpperWingCallNodePaths : new PathSet ( ) ,
149- selectedFunctionIndex : null ,
150149 selectedNetworkMarker : null ,
151150 lastSeenTransformCount : 0 ,
152151} ;
@@ -296,17 +295,19 @@ const viewOptionsPerThread: Reducer<ThreadViewOptionsPerThreads> = (
296295
297296 const threadState = _getThreadViewOptions ( state , threadsKey ) ;
298297
299- const previousSelectedFunction = threadState . selectedFunctionIndex ;
298+ const previousLowerWingPath = threadState . selectedLowerWingCallNodePath ;
299+ const isSameSelection =
300+ selectedFunctionIndex === null
301+ ? previousLowerWingPath . length === 0
302+ : previousLowerWingPath . length === 1 &&
303+ previousLowerWingPath [ 0 ] === selectedFunctionIndex ;
300304
301- // If the selected function doesn't actually change, let's return the previous
302- // state to avoid rerenders.
303- if ( selectedFunctionIndex === previousSelectedFunction ) {
305+ if ( isSameSelection ) {
304306 return state ;
305307 }
306308
307309 if ( selectedFunctionIndex !== null ) {
308310 return _updateThreadViewOptions ( state , threadsKey , {
309- selectedFunctionIndex,
310311 selectedLowerWingCallNodePath : [ selectedFunctionIndex ] ,
311312 expandedLowerWingCallNodePaths : new PathSet ( [
312313 [ selectedFunctionIndex ] ,
@@ -319,7 +320,10 @@ const viewOptionsPerThread: Reducer<ThreadViewOptionsPerThreads> = (
319320 }
320321
321322 return _updateThreadViewOptions ( state , threadsKey , {
322- selectedFunctionIndex,
323+ selectedLowerWingCallNodePath : [ ] ,
324+ expandedLowerWingCallNodePaths : new PathSet ( ) ,
325+ selectedUpperWingCallNodePath : [ ] ,
326+ expandedUpperWingCallNodePaths : new PathSet ( ) ,
323327 } ) ;
324328 }
325329 case 'CHANGE_INVERT_CALLSTACK' : {
@@ -459,8 +463,48 @@ const viewOptionsPerThread: Reducer<ThreadViewOptionsPerThreads> = (
459463 return state ;
460464 }
461465
462- const { transforms } = action . newUrlState . profileSpecific ;
463- return objectMap ( state , ( viewOptions , threadsKey ) => {
466+ const { transforms, selectedFunctions } = action . newUrlState . profileSpecific ;
467+
468+ // The selected function lives in URL state; mirror it into the per-thread
469+ // wing paths so that initial loads and back/forward navigation restore the
470+ // wings to the right function.
471+ const newState : ThreadViewOptionsPerThreads = { ...state } ;
472+ for ( const threadsKey of Object . keys ( selectedFunctions ) ) {
473+ const selectedFunctionIndex = selectedFunctions [ threadsKey ] ;
474+ const viewOptions = _getThreadViewOptions ( newState , threadsKey ) ;
475+ const previousLowerWingPath = viewOptions . selectedLowerWingCallNodePath ;
476+ const matchesExisting =
477+ selectedFunctionIndex === null
478+ ? previousLowerWingPath . length === 0
479+ : previousLowerWingPath . length === 1 &&
480+ previousLowerWingPath [ 0 ] === selectedFunctionIndex ;
481+ if ( matchesExisting ) {
482+ continue ;
483+ }
484+ if ( selectedFunctionIndex === null ) {
485+ newState [ threadsKey ] = {
486+ ...viewOptions ,
487+ selectedLowerWingCallNodePath : [ ] ,
488+ expandedLowerWingCallNodePaths : new PathSet ( ) ,
489+ selectedUpperWingCallNodePath : [ ] ,
490+ expandedUpperWingCallNodePaths : new PathSet ( ) ,
491+ } ;
492+ } else {
493+ newState [ threadsKey ] = {
494+ ...viewOptions ,
495+ selectedLowerWingCallNodePath : [ selectedFunctionIndex ] ,
496+ expandedLowerWingCallNodePaths : new PathSet ( [
497+ [ selectedFunctionIndex ] ,
498+ ] ) ,
499+ selectedUpperWingCallNodePath : [ selectedFunctionIndex ] ,
500+ expandedUpperWingCallNodePaths : new PathSet ( [
501+ [ selectedFunctionIndex ] ,
502+ ] ) ,
503+ } ;
504+ }
505+ }
506+
507+ return objectMap ( newState , ( viewOptions , threadsKey ) => {
464508 const transformStack = transforms [ threadsKey ] || [ ] ;
465509 const newTransformCount = transformStack . length ;
466510 const oldTransformCount = viewOptions . lastSeenTransformCount ;
0 commit comments