@@ -1077,21 +1077,28 @@ function hideOrUnhideAllChildren(finishedWork, isHidden) {
1077
1077
if ( node . tag === HostComponent ) {
1078
1078
if ( hostSubtreeRoot === null ) {
1079
1079
hostSubtreeRoot = node ;
1080
-
1081
- const instance = node . stateNode ;
1082
- if ( isHidden ) {
1083
- hideInstance ( instance ) ;
1084
- } else {
1085
- unhideInstance ( node . stateNode , node . memoizedProps ) ;
1080
+ try {
1081
+ const instance = node . stateNode ;
1082
+ if ( isHidden ) {
1083
+ hideInstance ( instance ) ;
1084
+ } else {
1085
+ unhideInstance ( node . stateNode , node . memoizedProps ) ;
1086
+ }
1087
+ } catch ( error ) {
1088
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
1086
1089
}
1087
1090
}
1088
1091
} else if ( node . tag === HostText ) {
1089
1092
if ( hostSubtreeRoot === null ) {
1090
- const instance = node . stateNode ;
1091
- if ( isHidden ) {
1092
- hideTextInstance ( instance ) ;
1093
- } else {
1094
- unhideTextInstance ( instance , node . memoizedProps ) ;
1093
+ try {
1094
+ const instance = node . stateNode ;
1095
+ if ( isHidden ) {
1096
+ hideTextInstance ( instance ) ;
1097
+ } else {
1098
+ unhideTextInstance ( instance , node . memoizedProps ) ;
1099
+ }
1100
+ } catch ( error ) {
1101
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
1095
1102
}
1096
1103
}
1097
1104
} else if (
@@ -1938,11 +1945,7 @@ function commitMutationEffects_complete(root: FiberRoot, lanes: Lanes) {
1938
1945
while ( nextEffect !== null ) {
1939
1946
const fiber = nextEffect ;
1940
1947
setCurrentDebugFiberInDEV ( fiber ) ;
1941
- try {
1942
- commitMutationEffectsOnFiber ( fiber , root , lanes ) ;
1943
- } catch ( error ) {
1944
- captureCommitPhaseError ( fiber , fiber . return , error ) ;
1945
- }
1948
+ commitMutationEffectsOnFiber ( fiber , root , lanes ) ;
1946
1949
resetCurrentDebugFiberInDEV ( ) ;
1947
1950
1948
1951
const sibling = fiber . sibling ;
@@ -1975,12 +1978,19 @@ function commitMutationEffectsOnFiber(
1975
1978
commitReconciliationEffects ( finishedWork ) ;
1976
1979
1977
1980
if ( flags & Update ) {
1978
- commitHookEffectListUnmount (
1979
- HookInsertion | HookHasEffect ,
1980
- finishedWork ,
1981
- finishedWork . return ,
1982
- ) ;
1983
- commitHookEffectListMount ( HookInsertion | HookHasEffect , finishedWork ) ;
1981
+ try {
1982
+ commitHookEffectListUnmount (
1983
+ HookInsertion | HookHasEffect ,
1984
+ finishedWork ,
1985
+ finishedWork . return ,
1986
+ ) ;
1987
+ commitHookEffectListMount (
1988
+ HookInsertion | HookHasEffect ,
1989
+ finishedWork ,
1990
+ ) ;
1991
+ } catch ( error ) {
1992
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
1993
+ }
1984
1994
// Layout effects are destroyed during the mutation phase so that all
1985
1995
// destroy functions for all fibers are called before any create functions.
1986
1996
// This prevents sibling component effects from interfering with each other,
@@ -1998,15 +2008,20 @@ function commitMutationEffectsOnFiber(
1998
2008
finishedWork ,
1999
2009
finishedWork . return ,
2000
2010
) ;
2001
- } finally {
2002
- recordLayoutEffectDuration ( finishedWork ) ;
2011
+ } catch ( error ) {
2012
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2003
2013
}
2014
+ recordLayoutEffectDuration ( finishedWork ) ;
2004
2015
} else {
2005
- commitHookEffectListUnmount (
2006
- HookLayout | HookHasEffect ,
2007
- finishedWork ,
2008
- finishedWork . return ,
2009
- ) ;
2016
+ try {
2017
+ commitHookEffectListUnmount (
2018
+ HookLayout | HookHasEffect ,
2019
+ finishedWork ,
2020
+ finishedWork . return ,
2021
+ ) ;
2022
+ } catch ( error ) {
2023
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2024
+ }
2010
2025
}
2011
2026
}
2012
2027
return ;
@@ -2016,7 +2031,7 @@ function commitMutationEffectsOnFiber(
2016
2031
2017
2032
if ( flags & Ref ) {
2018
2033
if ( current !== null ) {
2019
- commitDetachRef ( current ) ;
2034
+ safelyDetachRef ( current , current . return ) ;
2020
2035
}
2021
2036
}
2022
2037
return ;
@@ -2026,13 +2041,17 @@ function commitMutationEffectsOnFiber(
2026
2041
2027
2042
if ( flags & Ref ) {
2028
2043
if ( current !== null ) {
2029
- commitDetachRef ( current ) ;
2044
+ safelyDetachRef ( current , current . return ) ;
2030
2045
}
2031
2046
}
2032
2047
if ( supportsMutation ) {
2033
2048
if ( flags & ContentReset ) {
2034
2049
const instance : Instance = finishedWork . stateNode ;
2035
- resetTextContent ( instance ) ;
2050
+ try {
2051
+ resetTextContent ( instance ) ;
2052
+ } catch ( error ) {
2053
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2054
+ }
2036
2055
}
2037
2056
2038
2057
if ( flags & Update ) {
@@ -2050,14 +2069,22 @@ function commitMutationEffectsOnFiber(
2050
2069
const updatePayload : null | UpdatePayload = ( finishedWork . updateQueue : any ) ;
2051
2070
finishedWork . updateQueue = null ;
2052
2071
if ( updatePayload !== null ) {
2053
- commitUpdate (
2054
- instance ,
2055
- updatePayload ,
2056
- type ,
2057
- oldProps ,
2058
- newProps ,
2059
- finishedWork ,
2060
- ) ;
2072
+ try {
2073
+ commitUpdate (
2074
+ instance ,
2075
+ updatePayload ,
2076
+ type ,
2077
+ oldProps ,
2078
+ newProps ,
2079
+ finishedWork ,
2080
+ ) ;
2081
+ } catch ( error ) {
2082
+ captureCommitPhaseError (
2083
+ finishedWork ,
2084
+ finishedWork . return ,
2085
+ error ,
2086
+ ) ;
2087
+ }
2061
2088
}
2062
2089
}
2063
2090
}
@@ -2083,7 +2110,12 @@ function commitMutationEffectsOnFiber(
2083
2110
// this case.
2084
2111
const oldText : string =
2085
2112
current !== null ? current . memoizedProps : newText ;
2086
- commitTextUpdate ( textInstance , oldText , newText ) ;
2113
+
2114
+ try {
2115
+ commitTextUpdate ( textInstance , oldText , newText ) ;
2116
+ } catch ( error ) {
2117
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2118
+ }
2087
2119
}
2088
2120
}
2089
2121
return ;
@@ -2096,14 +2128,26 @@ function commitMutationEffectsOnFiber(
2096
2128
if ( current !== null ) {
2097
2129
const prevRootState : RootState = current . memoizedState ;
2098
2130
if ( prevRootState . isDehydrated ) {
2099
- commitHydratedContainer ( root . containerInfo ) ;
2131
+ try {
2132
+ commitHydratedContainer ( root . containerInfo ) ;
2133
+ } catch ( error ) {
2134
+ captureCommitPhaseError (
2135
+ finishedWork ,
2136
+ finishedWork . return ,
2137
+ error ,
2138
+ ) ;
2139
+ }
2100
2140
}
2101
2141
}
2102
2142
}
2103
2143
if ( supportsPersistence ) {
2104
2144
const containerInfo = root . containerInfo ;
2105
2145
const pendingChildren = root . pendingChildren ;
2106
- replaceContainerChildren ( containerInfo , pendingChildren ) ;
2146
+ try {
2147
+ replaceContainerChildren ( containerInfo , pendingChildren ) ;
2148
+ } catch ( error ) {
2149
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2150
+ }
2107
2151
}
2108
2152
}
2109
2153
return ;
@@ -2116,7 +2160,11 @@ function commitMutationEffectsOnFiber(
2116
2160
const portal = finishedWork . stateNode ;
2117
2161
const containerInfo = portal . containerInfo ;
2118
2162
const pendingChildren = portal . pendingChildren ;
2119
- replaceContainerChildren ( containerInfo , pendingChildren ) ;
2163
+ try {
2164
+ replaceContainerChildren ( containerInfo , pendingChildren ) ;
2165
+ } catch ( error ) {
2166
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2167
+ }
2120
2168
}
2121
2169
}
2122
2170
return ;
@@ -2136,7 +2184,11 @@ function commitMutationEffectsOnFiber(
2136
2184
}
2137
2185
}
2138
2186
if ( flags & Update ) {
2139
- commitSuspenseCallback ( finishedWork ) ;
2187
+ try {
2188
+ commitSuspenseCallback ( finishedWork ) ;
2189
+ } catch ( error ) {
2190
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2191
+ }
2140
2192
attachSuspenseRetryListeners ( finishedWork ) ;
2141
2193
}
2142
2194
return ;
@@ -2194,9 +2246,9 @@ function commitMutationEffectsOnFiber(
2194
2246
// from React Flare on www.
2195
2247
if ( flags & Ref ) {
2196
2248
if ( current !== null ) {
2197
- commitDetachRef ( current ) ;
2249
+ safelyDetachRef ( finishedWork , finishedWork . return ) ;
2198
2250
}
2199
- commitAttachRef ( finishedWork ) ;
2251
+ safelyAttachRef ( finishedWork , finishedWork . return ) ;
2200
2252
}
2201
2253
if ( flags & Update ) {
2202
2254
const scopeInstance = finishedWork . stateNode ;
@@ -2217,7 +2269,11 @@ function commitReconciliationEffects(finishedWork: Fiber) {
2217
2269
// before the effects on this fiber have fired.
2218
2270
const flags = finishedWork . flags ;
2219
2271
if ( flags & Placement ) {
2220
- commitPlacement ( finishedWork ) ;
2272
+ try {
2273
+ commitPlacement ( finishedWork ) ;
2274
+ } catch ( error ) {
2275
+ captureCommitPhaseError ( finishedWork , finishedWork . return , error ) ;
2276
+ }
2221
2277
// Clear the "placement" from effect tag so that we know that this is
2222
2278
// inserted, before any life-cycles like componentDidMount gets called.
2223
2279
// TODO: findDOMNode doesn't rely on this any more but isMounted does
0 commit comments