MCPcopy Create free account
hub / github.com/react/react / detachFiberMutation

Function detachFiberMutation

packages/react-reconciler/src/ReactFiberCommitWork.js:1248–1270  ·  view source on GitHub ↗
(fiber: Fiber)

Source from the content-addressed store, hash-verified

1246}
1247
1248function detachFiberMutation(fiber: Fiber) {
1249 // Cut off the return pointer to disconnect it from the tree.
1250 // This enables us to detect and warn against state updates on an unmounted component.
1251 // It also prevents events from bubbling from within disconnected components.
1252 //
1253 // Ideally, we should also clear the child pointer of the parent alternate to let this
1254 // get GC:ed but we don't know which for sure which parent is the current
1255 // one so we'll settle for GC:ing the subtree of this child.
1256 // This child itself will be GC:ed when the parent updates the next time.
1257 //
1258 // Note that we can't clear child or sibling pointers yet.
1259 // They're needed for passive effects and for findDOMNode.
1260 // We defer those fields, and all other cleanup, to the passive phase (see detachFiberAfterEffects).
1261 //
1262 // Don't reset the alternate yet, either. We need that so we can detach the
1263 // alternate's fields in the passive phase. Clearing the return pointer is
1264 // sufficient for findDOMNode semantics.
1265 const alternate = fiber.alternate;
1266 if (alternate !== null) {
1267 alternate.return = null;
1268 }
1269 fiber.return = null;
1270}
1271
1272function detachFiberAfterEffects(fiber: Fiber) {
1273 const alternate = fiber.alternate;

Callers 1

commitDeletionEffectsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected