@@ -36,6 +36,7 @@ import {
36
36
enableScopeAPI ,
37
37
enableStrictEffects ,
38
38
deletedTreeCleanUpLevel ,
39
+ enableUpdaterTracking ,
39
40
} from 'shared/ReactFeatureFlags' ;
40
41
import {
41
42
FunctionComponent ,
@@ -86,7 +87,7 @@ import {
86
87
resetCurrentFiber as resetCurrentDebugFiberInDEV ,
87
88
setCurrentFiber as setCurrentDebugFiberInDEV ,
88
89
} from './ReactCurrentFiber' ;
89
-
90
+ import { isDevToolsPresent } from './ReactFiberDevToolsHook.new' ;
90
91
import { onCommitUnmount } from './ReactFiberDevToolsHook.new' ;
91
92
import { resolveDefaultProps } from './ReactFiberLazyComponent.new' ;
92
93
import {
@@ -134,6 +135,7 @@ import {
134
135
resolveRetryWakeable ,
135
136
markCommitTimeOfFallback ,
136
137
enqueuePendingPassiveProfilerEffect ,
138
+ restorePendingUpdaters ,
137
139
} from './ReactFiberWorkLoop.new' ;
138
140
import {
139
141
NoFlags as NoHookEffect ,
@@ -1663,7 +1665,12 @@ function commitDeletion(
1663
1665
detachFiberMutation ( current ) ;
1664
1666
}
1665
1667
1666
- function commitWork ( current : Fiber | null , finishedWork : Fiber ) : void {
1668
+ function commitWork (
1669
+ finishedRoot : FiberRoot ,
1670
+ current : Fiber | null ,
1671
+ finishedWork : Fiber ,
1672
+ committedLanes : Lanes ,
1673
+ ) : void {
1667
1674
if ( ! supportsMutation ) {
1668
1675
switch ( finishedWork . tag ) {
1669
1676
case FunctionComponent :
@@ -1704,11 +1711,19 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1704
1711
}
1705
1712
case SuspenseComponent : {
1706
1713
commitSuspenseComponent ( finishedWork ) ;
1707
- attachSuspenseRetryListeners ( finishedWork ) ;
1714
+ attachSuspenseRetryListeners (
1715
+ finishedRoot ,
1716
+ finishedWork ,
1717
+ committedLanes ,
1718
+ ) ;
1708
1719
return ;
1709
1720
}
1710
1721
case SuspenseListComponent : {
1711
- attachSuspenseRetryListeners ( finishedWork ) ;
1722
+ attachSuspenseRetryListeners (
1723
+ finishedRoot ,
1724
+ finishedWork ,
1725
+ committedLanes ,
1726
+ ) ;
1712
1727
return ;
1713
1728
}
1714
1729
case HostRoot : {
@@ -1827,11 +1842,11 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
1827
1842
}
1828
1843
case SuspenseComponent : {
1829
1844
commitSuspenseComponent ( finishedWork ) ;
1830
- attachSuspenseRetryListeners ( finishedWork ) ;
1845
+ attachSuspenseRetryListeners ( finishedRoot , finishedWork , committedLanes ) ;
1831
1846
return ;
1832
1847
}
1833
1848
case SuspenseListComponent : {
1834
- attachSuspenseRetryListeners ( finishedWork ) ;
1849
+ attachSuspenseRetryListeners ( finishedRoot , finishedWork , committedLanes ) ;
1835
1850
return ;
1836
1851
}
1837
1852
case IncompleteClassComponent : {
@@ -1927,7 +1942,11 @@ function commitSuspenseHydrationCallbacks(
1927
1942
}
1928
1943
}
1929
1944
1930
- function attachSuspenseRetryListeners ( finishedWork : Fiber ) {
1945
+ function attachSuspenseRetryListeners (
1946
+ finishedRoot : FiberRoot ,
1947
+ finishedWork : Fiber ,
1948
+ committedLanes : Lanes ,
1949
+ ) {
1931
1950
// If this boundary just timed out, then it will have a set of wakeables.
1932
1951
// For each wakeable, attach a listener so that when it resolves, React
1933
1952
// attempts to re-render the boundary in the primary (pre-timeout) state.
@@ -1947,6 +1966,12 @@ function attachSuspenseRetryListeners(finishedWork: Fiber) {
1947
1966
retry = Schedule_tracing_wrap ( retry ) ;
1948
1967
}
1949
1968
}
1969
+ if ( enableUpdaterTracking ) {
1970
+ if ( isDevToolsPresent ) {
1971
+ // If we have pending work still, associate the original updaters with it.
1972
+ restorePendingUpdaters ( finishedRoot , committedLanes ) ;
1973
+ }
1974
+ }
1950
1975
retryCache . add ( wakeable ) ;
1951
1976
wakeable . then ( retry , retry ) ;
1952
1977
}
@@ -1978,12 +2003,16 @@ function commitResetTextContent(current: Fiber) {
1978
2003
resetTextContent ( current . stateNode ) ;
1979
2004
}
1980
2005
1981
- export function commitMutationEffects ( root : FiberRoot , firstChild : Fiber ) {
2006
+ export function commitMutationEffects (
2007
+ root : FiberRoot ,
2008
+ firstChild : Fiber ,
2009
+ committedLanes : Lanes ,
2010
+ ) {
1982
2011
nextEffect = firstChild ;
1983
- commitMutationEffects_begin ( root ) ;
2012
+ commitMutationEffects_begin ( root , committedLanes ) ;
1984
2013
}
1985
2014
1986
- function commitMutationEffects_begin ( root : FiberRoot ) {
2015
+ function commitMutationEffects_begin ( root : FiberRoot , committedLanes : Lanes ) {
1987
2016
while ( nextEffect !== null ) {
1988
2017
const fiber = nextEffect ;
1989
2018
@@ -2020,12 +2049,15 @@ function commitMutationEffects_begin(root: FiberRoot) {
2020
2049
ensureCorrectReturnPointer ( child , fiber ) ;
2021
2050
nextEffect = child ;
2022
2051
} else {
2023
- commitMutationEffects_complete ( root ) ;
2052
+ commitMutationEffects_complete ( root , committedLanes ) ;
2024
2053
}
2025
2054
}
2026
2055
}
2027
2056
2028
- function commitMutationEffects_complete ( root : FiberRoot ) {
2057
+ function commitMutationEffects_complete (
2058
+ root : FiberRoot ,
2059
+ committedLanes : Lanes ,
2060
+ ) {
2029
2061
while ( nextEffect !== null ) {
2030
2062
const fiber = nextEffect ;
2031
2063
if ( __DEV__ ) {
@@ -2036,6 +2068,7 @@ function commitMutationEffects_complete(root: FiberRoot) {
2036
2068
null ,
2037
2069
fiber ,
2038
2070
root ,
2071
+ committedLanes ,
2039
2072
) ;
2040
2073
if ( hasCaughtError ( ) ) {
2041
2074
const error = clearCaughtError ( ) ;
@@ -2044,7 +2077,7 @@ function commitMutationEffects_complete(root: FiberRoot) {
2044
2077
resetCurrentDebugFiberInDEV ( ) ;
2045
2078
} else {
2046
2079
try {
2047
- commitMutationEffectsOnFiber ( fiber , root ) ;
2080
+ commitMutationEffectsOnFiber ( fiber , root , committedLanes ) ;
2048
2081
} catch ( error ) {
2049
2082
captureCommitPhaseError ( fiber , fiber . return , error ) ;
2050
2083
}
@@ -2061,7 +2094,11 @@ function commitMutationEffects_complete(root: FiberRoot) {
2061
2094
}
2062
2095
}
2063
2096
2064
- function commitMutationEffectsOnFiber ( finishedWork : Fiber , root : FiberRoot ) {
2097
+ function commitMutationEffectsOnFiber (
2098
+ finishedWork : Fiber ,
2099
+ root : FiberRoot ,
2100
+ committedLanes : Lanes ,
2101
+ ) {
2065
2102
const flags = finishedWork . flags ;
2066
2103
2067
2104
if ( flags & ContentReset ) {
@@ -2106,7 +2143,7 @@ function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) {
2106
2143
2107
2144
// Update
2108
2145
const current = finishedWork . alternate ;
2109
- commitWork ( current , finishedWork ) ;
2146
+ commitWork ( root , current , finishedWork , committedLanes ) ;
2110
2147
break ;
2111
2148
}
2112
2149
case Hydrating : {
@@ -2118,12 +2155,12 @@ function commitMutationEffectsOnFiber(finishedWork: Fiber, root: FiberRoot) {
2118
2155
2119
2156
// Update
2120
2157
const current = finishedWork . alternate ;
2121
- commitWork ( current , finishedWork ) ;
2158
+ commitWork ( root , current , finishedWork , committedLanes ) ;
2122
2159
break ;
2123
2160
}
2124
2161
case Update : {
2125
2162
const current = finishedWork . alternate ;
2126
- commitWork ( current , finishedWork ) ;
2163
+ commitWork ( root , current , finishedWork , committedLanes ) ;
2127
2164
break ;
2128
2165
}
2129
2166
}
0 commit comments