-
-
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
onBecomeUnobserved
not triggered immediately on useObserver
component unmount
#3774
Comments
It only reproduces with |
same issue with react suspense: https://codesandbox.io/s/goofy-wright-kmpjxd?file=/src/App.tsx |
Ideas:
This approach tries to reach two goals:
Why to use
|
Does it work for both examples? |
Yes, it's released, but the delay is long; for example, if I want to track used resources to load them asynchronously, it will cause loading data even when a component is already unmounted. |
Yes, the suspense example actually unobserved immediately upon clicking the btn on the first try. It depends on GC, so it's a bit random, which I agree isn't ideal, but I wouldn't expect changes here anytime soon. Ideally use
You also have to diff saved and current values as your state could be changed before mount. We were considering these before. I am a bit afraid that the machinery involved could often end up being slower or comparable to just scheduling another render on mount... |
I see. Why are you using setTimeout with a custom timeout to clear lost reactions? Theoretically, when the component hasn't been rendered on the following browser's repaint, it's optimized by React and it will be rendered in the following frames, or the render has been interrupted by StrictMode or Suspense. |
…de and Suspense onBecomeUnobserved never triggered with observer component mobxjs#3774
I created a pull request that includes the use of |
onBecomeUnobserved
not triggered immediately on useObserver
component unmount
I just encountered this bug too. I made a reproduction, not sure if it helps but I'll link it just in case. |
Intended outcome:
onBecomeUnobserved
triggered when the component wrapped withobserver
is unmountedActual outcome:
onBecomeUnobserved
never triggered or triggered randomlyHow to reproduce the issue:
https://codesandbox.io/s/practical-ioana-6sthfs?file=/src/App.tsx
Versions
seems like it's reproduced on any version
The text was updated successfully, but these errors were encountered: