-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
fix(utils): fix memory leaks and other issues in atomWithObservable #1170
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ed10d98:
|
Hi, thanks for working on it. I'll have a look later. |
3394e56
to
82d9279
Compare
82d9279
to
dfb6262
Compare
I updated the MR. To my earlier point:
I don't think that this would be a good idea anymore. I think in some scenarios the timeout just cannot be avoided and in these cases warning logs would be pretty annoying. |
I see that a test is failing. I will look into it later (probably tomorrow). |
You seem to be misunderstanding something, at least from my understanding. I would expect to clear timeout on mount. So, 1 second is mostly enough (or we don't know for sure anyways). It's not about first emitting. |
@dai-shi My understanding was, if the first value doesn't emit the "loading" indicator from the suspense is always shown. This way the This test should reproduce the behaviour: jotai/tests/utils/atomWithObservable.test.tsx Lines 246 to 277 in dfb6262
This is always throws: So this never gets called (which calls onMount): But I will test my assumptions again and create a code sandbox to reproduce the memory leak in a real app. Maybe this was a misunderstanding on my side. |
Oh, yeah. You are right. Hm, what was I confused with.. Okay, in such a case, I think the default behavior is no timeout, pending infinitely. |
Okay, I will update the default accordingly 👍 |
bdaf9d9
to
3abbe50
Compare
@dai-shi I just figured out, that the subscription only get's leaked if the As this is a pretty uncommon edge case and the timeout can introduce other bugs, I decided to just completely remove it. This also makes the code a little less complicated. We could avoid the leak completely if the I also fixed the tests. So this MR should be ready. |
This is only true in React 17. React 18 can invoke render multiple time before comitting for various reasons. jotai atom's See more here: facebook/react#15317
That said, it's fine for now, but I'd like to leave some comments about the memory leak risk. |
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.
Some minor comments.
Should I add the comments in the code or in the documentation? |
In the code, please. |
8fccdb5
to
48a9fa3
Compare
48a9fa3
to
ed10d98
Compare
I added the comment. |
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.
Looks good. Thanks for your contribution.
I'll merge it when we are ready to cut a new release.
@dai-shi As discussed this PR builds on #1157
This is the test result with the current implementation:
This is the test result new implementation:
Fixed issues:
0
,false
,''
, etc.)BehaviourSubject
or already has a value,Suspense
is no longer required.timeout
optiontimeout
gets applied. This way the user knows that something went wrong and can fix the issue (What are your thoughts on that?)I'm looking forward to your thoughts and feedback!