You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We currently run all passive destroy functions for an individual Fiber before running passive create functions. What we should be doing is running all passive destroy functions for all fibers before running any passive create functions (like we do for layout effects).
The reason this is important is that interleaving destroy/create effects between sibling components might cause components to interfere with each other (e.g. a destroy function in one component may unintentionally override a ref value set by a create function in another component).
We handle this for layout effects by invoking all destroy functions during the "mutation" phase and all create functions during the "layout" phase, but for passive effects we call both in a single traversal:
invariant(effect!==null,'Should be working on an effect.');
consterror=clearCaughtError();
captureCommitPhaseError(effect,error);
}
resetCurrentDebugFiberInDEV();
}else{
try{
commitPassiveHookEffects(effect);
}catch(error){
invariant(effect!==null,'Should be working on an effect.');
captureCommitPhaseError(effect,error);
}
}
constnextNextEffect=effect.nextEffect;
// Remove nextEffect pointer to assist GC
effect.nextEffect=null;
effect=nextNextEffect;
}
However this could be a breaking change (since it would affect timing) so we should probably do it behind a feature flag for now.
Also note that splitting this into two passes could have another unintended effect: an error thrown in a passive destroy function would no longer prevent subsequent create functions from being run on that Fiber (as is currently the case) unless we added code to handle that specific case. We should decide what the expected behavior is here.
The text was updated successfully, but these errors were encountered:
We currently run all passive destroy functions for an individual Fiber before running passive create functions. What we should be doing is running all passive destroy functions for all fibers before running any passive create functions (like we do for layout effects).
The reason this is important is that interleaving destroy/create effects between sibling components might cause components to interfere with each other (e.g. a destroy function in one component may unintentionally override a ref value set by a create function in another component).
We handle this for layout effects by invoking all destroy functions during the "mutation" phase and all create functions during the "layout" phase, but for passive effects we call both in a single traversal:
react/packages/react-reconciler/src/ReactFiberCommitWork.js
Lines 394 to 409 in 38cd758
Fixing this probably means splitting our passive effects loop into two passes:
react/packages/react-reconciler/src/ReactFiberWorkLoop.js
Lines 2179 to 2222 in 38cd758
However this could be a breaking change (since it would affect timing) so we should probably do it behind a feature flag for now.
Also note that splitting this into two passes could have another unintended effect: an error thrown in a passive destroy function would no longer prevent subsequent create functions from being run on that Fiber (as is currently the case) unless we added code to handle that specific case. We should decide what the expected behavior is here.
The text was updated successfully, but these errors were encountered: