Repository navigation
[Web LA] Fix interaction with react-freeze - #7114
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the web layout reanimation “exiting” flow to better interoperate with react-freeze by hiding the original element during exit and reparenting children back to the original element once the dummy’s exit animation completes/cancels.
Changes:
- Hide the original element while its dummy clone performs the exiting animation.
- Add cleanup logic to reparent children back to the original element after the dummy animation ends/cancels and remove the dummy.
- Update
setElementAnimationAPI to accept anoriginalElementreference for the exiting-animation cleanup path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
m-bert
left a comment
There was a problem hiding this comment.
Also I've noticed that in the given repro, when adding child, at first yellow circle drops down to its previous position and then animates, but I think it is a case for other PR.
MatiPl01
left a comment
There was a problem hiding this comment.
Seems to be correct, thanks!
Summary
Preface
This issue was reported in Expensify.
In order for
exitinganimation to work, we have to prolong component's life. We do this by creating a copy of it and then assigning animation to the clone. The problem is that we cannot simply useelement.cloneNode(true)as cloning children this way would create a copy, therefore if they also haveexitinganimation it would be assigned into original children. Here we have two issues:Problem 1. is solved by adding
Second one was solved by using the following loop:
appendChildmoves node into another place in the tree without making a copy. This approach made nestedexitinganimations easier.react-freezeThere's a catch. With
react-freeze, component is not unmounted from HTML tree - it just becomes invisible. When weunfreezecomponent, it goes back to being visible, but if it hadexitinganimation, its children were moved into its cloned. Therefore, if anything (for exampleReact) would try to modify subtree of given node, it would throw error (for example using methods likeinsertBeforeorremoveChild)Solution
To make
exitingwork withreact-freeze, we add logic that once more performs reparenting, moving children again to its original parent after animation finishes (or gets cancelled).If
freezewas not used, then these children will be unmounted anyway, but iffreezewas used,Reactcan now properly interact with children.Other possibilities
We also tried one more solution - clone children and place them in the original parent. However, it still throws errors. My guess is that either
cloneNodedoesn't create exact copy (using===operator yieldsfalse) or there are more conditions that have to be met when using methods likeinsertBefore.Test plan
Tested on the following code: