-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition when swapping nodes between <OutPortal/>s #15
Comments
I haven't seen this case before, but it makes sense. The core of the issue is in the unmount nodeB during OutPortalB's componentDidUpdate, right? I'm not affected by this myself, but I'd like to support it, and I'd certainly accept a fix. It sounds like it should be easy to set up a story to easily reproduce the issue, which would be a good start. I suspect the underlying bug is that we omit the react-reverse-portal/src/index.tsx Lines 200 to 204 in 088033e
Meanwhile we do specify this in react-reverse-portal/src/index.tsx Lines 212 to 215 in 088033e
I haven't checked, but you can probably just change the former to also pass That Can you give that a go? |
Thanks for your answer, I will try it and keep you updated |
It seems to work well ! Here is the PR #16 |
Fix is now merged and released and it sounds like it solves your issue so I'm going to close this, but do shout if you're still seeing issues related to this. |
I tested it on my own project and it works well 👍 Thanks for your quick answer and release |
Problem
Hi, I want to use this library to be able to move some components in a layout, without having to unmount/remount them. However, I am unable to do so because of race conditions when swapping nodes betwing two
<OutPortal/>
s within a single rerender.Cause
Here is a very simplified example that shows what happens:
Suppose I have two nodes NodeA and NodeB created once and for all.
Now suppose down the line we use those nodes in a layout, that would look like this at the first render.
Then, suppose an update arrives, yielding the following instead:
Here is roughly what happens when going through the code of
react-reverse-portal
:OutPortal1 componentDidUpdate is triggered, with nodeB instead of nodeA
OutPortalB componentDidUpdate is triggered with nodeA instead of nodeB
Because of this race condition, we end up having OutPortal1 yielding Placeholder1 and OutPortal2 yielding NodeA, even though we just wanted to swap the nodes.
Note: this is a very simplified example, but my real use-case involves a recursive layout with potentially many content nodes.
Question
Are there any plans on handling this use case ? Can you think of a workaround ?
The text was updated successfully, but these errors were encountered: