Fix: observer class components going stale after 10 seconds #3776
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After upgrading from MobX 4 to MobX 6 in a React Native project (React 18.2, no StrictMode), I noticed almost all of my screens went stale shortly after rendering.
An observer class component is registered with
observerFinalizationRegistry
like so:The third argument is the
token
, which is used to store the registration in a Map. IncomponentDidMount
the finalization is then unregistered so it is allowed to stay alive, but usingadmin
as the token, notthis
:admin
is not registered to begin with, so the finalization does not get cleaned up, resulting in every class component going stale after about 10 seconds of being rendered.Code change checklist
/docs
. For new functionality, at leastAPI.md
should be updatedyarn mobx test:performance
)Happy to write tests for this - but I will need some pointers. I saw the
finalizationRegistry
test, but it is not immediately obvious to me how I should approach testing registration and deregistration.