-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
onBecome(Un)Observed intercept hooks can remove each other #1537
Comments
Hey @mweststrate I'll be happy to try to fix this issue. Is there anything I should take into account before doing that? Any suggestions or we can discuss it after I try to implement it? |
Hey! Feel free to open a PR, it is probably easier to discuss with some
code at hand :-)
Op ma 1 okt. 2018 om 11:25 schreef Michał Warda <[email protected]>:
… Hey @mweststrate <https://github.com/mweststrate> I'll be happy to try to
fix this issue. Is there anything I should take into account before doing
that? Any suggestions or we can discuss it after I try to implement it?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1537 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhEYMZI-xvz0rgpsg08usOhC-9eSNks5ugd-egaJpZM4T3ACs>
.
|
@mweststrate Do you have any suggestions on how can we continue this? I have some time currently so I can adjust the PR. |
fix: earlier onBecome(Un)Observed disposer will not dispose later listener (fix #1537)
released in 4.8.0 / 5.8.0 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
The way
onBecomeObserved
andonBecomeUnobserved
are implemented means they can inadvertently cancel each other.Source of the issue is here:
https://github.com/mobxjs/mobx/blob/master/src/api/become-observed.ts#L44
If you add a hook, the behaviour is 'call the original hook, then the new one'. The disposer function that is returned has the behavior of 'restore the original hook'.
This means that if a hook is disposed (with the return value), any subsequent hooks added since that was added will also be removed. Example here:
https://codesandbox.io/s/k0y70x7vy7
(You'd expect one of the two callbacks be called, but it isn't because the first was removed).
I started a fix for this, but the solution wasn't as immediately straightforward as I thought and since I don't know when I'll have time to give it another go I wanted to record this for now.
The text was updated successfully, but these errors were encountered: