Description
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.