@@ -153,11 +153,7 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
153
153
} ;
154
154
155
155
// Capture errors so they don't interrupt unmounting.
156
- function safelyCallComponentWillUnmount (
157
- current : Fiber ,
158
- instance : any ,
159
- nearestMountedAncestor : Fiber | null ,
160
- ) {
156
+ function safelyCallComponentWillUnmount ( current : Fiber , instance : any ) {
161
157
if ( __DEV__ ) {
162
158
invokeGuardedCallback (
163
159
null ,
@@ -168,32 +164,32 @@ function safelyCallComponentWillUnmount(
168
164
) ;
169
165
if ( hasCaughtError ( ) ) {
170
166
const unmountError = clearCaughtError ( ) ;
171
- captureCommitPhaseError ( current , nearestMountedAncestor , unmountError ) ;
167
+ captureCommitPhaseError ( current , unmountError ) ;
172
168
}
173
169
} else {
174
170
try {
175
171
callComponentWillUnmountWithTimer ( current , instance ) ;
176
172
} catch ( unmountError ) {
177
- captureCommitPhaseError ( current , nearestMountedAncestor , unmountError ) ;
173
+ captureCommitPhaseError ( current , unmountError ) ;
178
174
}
179
175
}
180
176
}
181
177
182
- function safelyDetachRef ( current : Fiber , nearestMountedAncestor : Fiber | null ) {
178
+ function safelyDetachRef ( current : Fiber ) {
183
179
const ref = current . ref ;
184
180
if ( ref !== null ) {
185
181
if ( typeof ref === 'function' ) {
186
182
if ( __DEV__ ) {
187
183
invokeGuardedCallback ( null , ref , null , null ) ;
188
184
if ( hasCaughtError ( ) ) {
189
185
const refError = clearCaughtError ( ) ;
190
- captureCommitPhaseError ( current , nearestMountedAncestor , refError ) ;
186
+ captureCommitPhaseError ( current , refError ) ;
191
187
}
192
188
} else {
193
189
try {
194
190
ref ( null ) ;
195
191
} catch ( refError ) {
196
- captureCommitPhaseError ( current , nearestMountedAncestor , refError ) ;
192
+ captureCommitPhaseError ( current , refError ) ;
197
193
}
198
194
}
199
195
} else {
@@ -202,22 +198,18 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
202
198
}
203
199
}
204
200
205
- function safelyCallDestroy (
206
- current : Fiber ,
207
- nearestMountedAncestor : Fiber | null ,
208
- destroy : ( ) = > void ,
209
- ) {
201
+ function safelyCallDestroy ( current : Fiber , destroy : ( ) = > void ) {
210
202
if ( __DEV__ ) {
211
203
invokeGuardedCallback ( null , destroy , null ) ;
212
204
if ( hasCaughtError ( ) ) {
213
205
const error = clearCaughtError ( ) ;
214
- captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
206
+ captureCommitPhaseError ( current , error ) ;
215
207
}
216
208
} else {
217
209
try {
218
210
destroy ( ) ;
219
211
} catch ( error ) {
220
- captureCommitPhaseError ( current , nearestMountedAncestor , error ) ;
212
+ captureCommitPhaseError ( current , error ) ;
221
213
}
222
214
}
223
215
}
@@ -874,7 +866,6 @@ function commitDetachRef(current: Fiber) {
874
866
function commitUnmount (
875
867
finishedRoot : FiberRoot ,
876
868
current : Fiber ,
877
- nearestMountedAncestor : Fiber | null ,
878
869
renderPriorityLevel : ReactPriorityLevel ,
879
870
) : void {
880
871
onCommitUnmount ( current ) ;
@@ -904,10 +895,10 @@ function commitUnmount(
904
895
current . mode & ProfileMode
905
896
) {
906
897
startLayoutEffectTimer ( ) ;
907
- safelyCallDestroy ( current , nearestMountedAncestor , destroy ) ;
898
+ safelyCallDestroy ( current , destroy ) ;
908
899
recordLayoutEffectDuration ( current ) ;
909
900
} else {
910
- safelyCallDestroy ( current , nearestMountedAncestor , destroy ) ;
901
+ safelyCallDestroy ( current , destroy ) ;
911
902
}
912
903
}
913
904
}
@@ -918,32 +909,23 @@ function commitUnmount(
918
909
return ;
919
910
}
920
911
case ClassComponent : {
921
- safelyDetachRef ( current , nearestMountedAncestor ) ;
912
+ safelyDetachRef ( current ) ;
922
913
const instance = current . stateNode ;
923
914
if ( typeof instance . componentWillUnmount === 'function' ) {
924
- safelyCallComponentWillUnmount (
925
- current ,
926
- instance ,
927
- nearestMountedAncestor ,
928
- ) ;
915
+ safelyCallComponentWillUnmount ( current , instance ) ;
929
916
}
930
917
return ;
931
918
}
932
919
case HostComponent : {
933
- safelyDetachRef ( current , nearestMountedAncestor ) ;
920
+ safelyDetachRef ( current ) ;
934
921
return ;
935
922
}
936
923
case HostPortal : {
937
924
// TODO: this is recursive.
938
925
// We are also not using this parent because
939
926
// the portal will get pushed immediately.
940
927
if ( supportsMutation ) {
941
- unmountHostComponents (
942
- finishedRoot ,
943
- current ,
944
- nearestMountedAncestor ,
945
- renderPriorityLevel ,
946
- ) ;
928
+ unmountHostComponents ( finishedRoot , current , renderPriorityLevel ) ;
947
929
} else if ( supportsPersistence ) {
948
930
emptyPortalContainer ( current ) ;
949
931
}
@@ -973,7 +955,7 @@ function commitUnmount(
973
955
}
974
956
case ScopeComponent : {
975
957
if ( enableScopeAPI ) {
976
- safelyDetachRef ( current , nearestMountedAncestor ) ;
958
+ safelyDetachRef ( current ) ;
977
959
}
978
960
return ;
979
961
}
@@ -983,7 +965,6 @@ function commitUnmount(
983
965
function commitNestedUnmounts (
984
966
finishedRoot : FiberRoot ,
985
967
root : Fiber ,
986
- nearestMountedAncestor : Fiber | null ,
987
968
renderPriorityLevel : ReactPriorityLevel ,
988
969
) : void {
989
970
// While we're inside a removed host node we don't want to call
@@ -993,12 +974,7 @@ function commitNestedUnmounts(
993
974
// we do an inner loop while we're still inside the host node.
994
975
let node : Fiber = root ;
995
976
while ( true ) {
996
- commitUnmount (
997
- finishedRoot ,
998
- node ,
999
- nearestMountedAncestor ,
1000
- renderPriorityLevel ,
1001
- ) ;
977
+ commitUnmount ( finishedRoot , node , renderPriorityLevel ) ;
1002
978
// Visit children because they may contain more composite or host nodes.
1003
979
// Skip portals because commitUnmount() currently visits them recursively.
1004
980
if (
@@ -1289,7 +1265,6 @@ function insertOrAppendPlacementNode(
1289
1265
function unmountHostComponents (
1290
1266
finishedRoot : FiberRoot ,
1291
1267
current : Fiber ,
1292
- nearestMountedAncestor : Fiber | null ,
1293
1268
renderPriorityLevel : ReactPriorityLevel ,
1294
1269
) : void {
1295
1270
// We only have the top Fiber that was deleted but we need to recurse down its
@@ -1339,12 +1314,7 @@ function unmountHostComponents(
1339
1314
}
1340
1315
1341
1316
if ( node . tag === HostComponent || node . tag === HostText ) {
1342
- commitNestedUnmounts (
1343
- finishedRoot ,
1344
- node ,
1345
- nearestMountedAncestor ,
1346
- renderPriorityLevel ,
1347
- ) ;
1317
+ commitNestedUnmounts ( finishedRoot , node , renderPriorityLevel ) ;
1348
1318
// After all the children have unmounted, it is now safe to remove the
1349
1319
// node from the tree.
1350
1320
if ( currentParentIsContainer ) {
@@ -1361,12 +1331,7 @@ function unmountHostComponents(
1361
1331
// Don't visit children because we already visited them.
1362
1332
} else if ( enableFundamentalAPI && node . tag === FundamentalComponent ) {
1363
1333
const fundamentalNode = node . stateNode . instance ;
1364
- commitNestedUnmounts (
1365
- finishedRoot ,
1366
- node ,
1367
- nearestMountedAncestor ,
1368
- renderPriorityLevel ,
1369
- ) ;
1334
+ commitNestedUnmounts ( finishedRoot , node , renderPriorityLevel ) ;
1370
1335
// After all the children have unmounted, it is now safe to remove the
1371
1336
// node from the tree.
1372
1337
if ( currentParentIsContainer ) {
@@ -1418,12 +1383,7 @@ function unmountHostComponents(
1418
1383
continue ;
1419
1384
}
1420
1385
} else {
1421
- commitUnmount (
1422
- finishedRoot ,
1423
- node ,
1424
- nearestMountedAncestor ,
1425
- renderPriorityLevel ,
1426
- ) ;
1386
+ commitUnmount ( finishedRoot , node , renderPriorityLevel ) ;
1427
1387
// Visit children because we may find more host components below.
1428
1388
if ( node . child !== null ) {
1429
1389
node . child . return = node ;
@@ -1453,26 +1413,15 @@ function unmountHostComponents(
1453
1413
function commitDeletion (
1454
1414
finishedRoot : FiberRoot ,
1455
1415
current : Fiber ,
1456
- nearestMountedAncestor : Fiber | null ,
1457
1416
renderPriorityLevel : ReactPriorityLevel ,
1458
1417
) : void {
1459
1418
if ( supportsMutation ) {
1460
1419
// Recursively delete all host nodes from the parent.
1461
1420
// Detach refs and call componentWillUnmount() on the whole subtree.
1462
- unmountHostComponents (
1463
- finishedRoot ,
1464
- current ,
1465
- nearestMountedAncestor ,
1466
- renderPriorityLevel ,
1467
- ) ;
1421
+ unmountHostComponents ( finishedRoot , current , renderPriorityLevel ) ;
1468
1422
} else {
1469
1423
// Detach refs and call componentWillUnmount() on the whole subtree.
1470
- commitNestedUnmounts (
1471
- finishedRoot ,
1472
- current ,
1473
- nearestMountedAncestor ,
1474
- renderPriorityLevel ,
1475
- ) ;
1424
+ commitNestedUnmounts ( finishedRoot , current , renderPriorityLevel ) ;
1476
1425
}
1477
1426
const alternate = current . alternate ;
1478
1427
detachFiberMutation ( current ) ;
0 commit comments