-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Use a single global infinite promise #34
Conversation
Thanks for sending the PR. I don't remember if we'd ever consider doing this in proposed way and as you suggested it is likely due to the fact we weren't familiar with this pattern. As for the issue with initial mount that you mentioned, is it reported somewhere? As for the actual change, one thing that I wonder is whether this could potentially result in memory leaks? My understanding is that what React does under the hood, is it calls |
I wonder if we could just override |
No. I don't mean that it's an actual issue that shows up today. I meant that with a Concurrent Root (on the web, this corresponds to
Hm, interesting! Next.js does use this pattern, but I'm not sure if this is a concern.
Yes, that should work fine. (On the React side, it's how a built-in version of this will be implemented.) |
Pushed a fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for a long turnaround here. This looks good after the change. Will merge this in and will make a new release early next week. Thank you!
See the matching PR on react-freeze software-mansion/react-freeze#34 - the ref could get thrown away so not safe, plus not needed. Removed the copyright because don't think it's needed - it's only 1 line of code that is pretty well known now (React supsending on thrown promise)
It's not super clear why the code is written this way, but I assume it's due to not being familiar with the pattern. If you want to wait until the
freeze
prop changes, it's enough to throw a Promise that never resolves.This fixes an issue that would occur on initial mount with
createRoot
and/or Fabric. The issue is that React throws away uncommitted trees if they suspend during mount, and this includes throwing awayuseRef
. So stashing Promises inuseRef
is wrong. Having one at the top level is both safe and simpler.