File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1162,14 +1162,6 @@ function renderRoot(
11621162
11631163 const expirationTime = root . nextExpirationTimeToWorkOn ;
11641164
1165- let prevInteractions : Set < Interaction > = ( null : any ) ;
1166- if ( enableSchedulerTracking ) {
1167- // We're about to start new tracked work.
1168- // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
1169- prevInteractions = __interactionsRef . current ;
1170- __interactionsRef . current = root . memoizedInteractions ;
1171- }
1172-
11731165 // Check if we're starting from a fresh stack, or if we're resuming from
11741166 // previously yielded work.
11751167 if (
@@ -1232,6 +1224,14 @@ function renderRoot(
12321224 }
12331225 }
12341226
1227+ let prevInteractions : Set < Interaction > = ( null : any ) ;
1228+ if ( enableSchedulerTracking ) {
1229+ // We're about to start new tracked work.
1230+ // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
1231+ prevInteractions = __interactionsRef . current ;
1232+ __interactionsRef . current = root . memoizedInteractions ;
1233+ }
1234+
12351235 let didFatal = false ;
12361236
12371237 startWorkLoopTimer ( nextUnitOfWork ) ;
Original file line number Diff line number Diff line change @@ -1410,6 +1410,34 @@ describe('Profiler', () => {
14101410 } ) ;
14111411 } ) ;
14121412
1413+ it ( 'should properly track work scheduled during the begin render phase' , ( ) => {
1414+ const callback = jest . fn ( ) ;
1415+ let wrapped ;
1416+ const Component = jest . fn ( ( ) => {
1417+ wrapped = SchedulerTracking . unstable_wrap ( callback ) ;
1418+ return null ;
1419+ } ) ;
1420+
1421+ let interaction ;
1422+ SchedulerTracking . unstable_track ( 'event' , mockNow ( ) , ( ) => {
1423+ const interactions = SchedulerTracking . unstable_getCurrent ( ) ;
1424+ expect ( interactions . size ) . toBe ( 1 ) ;
1425+ interaction = Array . from ( interactions ) [ 0 ] ;
1426+ ReactTestRenderer . create ( < Component /> ) ;
1427+ } ) ;
1428+
1429+ expect ( Component ) . toHaveBeenCalledTimes ( 1 ) ;
1430+ expect ( onInteractionScheduledWorkCompleted ) . not . toHaveBeenCalled ( ) ;
1431+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
1432+
1433+ wrapped ( ) ;
1434+ expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
1435+ expect ( onInteractionScheduledWorkCompleted ) . toHaveBeenCalledTimes ( 1 ) ;
1436+ expect (
1437+ onInteractionScheduledWorkCompleted ,
1438+ ) . toHaveBeenLastNotifiedOfInteraction ( interaction ) ;
1439+ } ) ;
1440+
14131441 it ( 'should associate tracked events with their subsequent commits' , ( ) => {
14141442 let instance = null ;
14151443
You can’t perform that action at this time.
0 commit comments