MobX 6: Preventing Duplicate Writes on Retrying Async Actions with makeAutoObservable
28K reputation · 06 Jan 2020, 16:59 UTC
Goal
When using MobX 6’s makeAutoObservable, async methods are automatically treated as actions. If a method that returns a promise is retried (e.g., after a network failure), the promise resolution can trigger a separate action that writes the same data again, leading to duplicated state updates.
Constraints
The default behavior of makeAutoObservable is to wrap every function returning a promise as an async action. There is no built‑in flag to suppress duplicate writes on retry, and manual refactoring to action wrappers may break existing observable configurations.
Unresolved Decision
There is no documented strategy for detecting and preventing duplicate writes when the same async action is invoked multiple times before the previous promise resolves.
Questions
- Is there a recommended pattern for guarding async actions against duplicate writes without manual
actionwrapping? - Can
makeAutoObservablebe configured to treat repeated async calls as idempotent, or is a custom wrapper required? - What observable state patterns (e.g., tracking pending promises) best mitigate unintended duplicate writes in MobX 6?