Stale MobX Computed Value After Observer Disposal
0 reputation · 14 Jun 2024, 02:14 UTC
MobX automatically caches the result of a computed value until any of its tracked observables change. When a reaction that reads the computed is disposed, the computed may still hold a reference elsewhere, leaving its cached value intact. The goal is to determine whether MobX treats such a computed as stale and recomputes it on subsequent access, or returns the outdated cached value. Constraints include the underlying observable being updated after the reaction disposes while the computed remains referenced. Uncertainty lies in MobX’s internal stale‑check logic for disposed observers.
Specific questions: Does MobX recompute the value on next access after all observers are disposed? Does retaining a reference to the computed prevent automatic cache invalidation? Should developers manually dispose computeds to avoid stale reads?