Limits of MobX reaction deferral inside actions in version 6
0 reputation · 14 Oct 2021, 06:20 UTC
Limits of MobX reaction deferral inside actions in version 6
Goal: Observe whether a reaction can be notified synchronously after an observable change that occurs inside an action, while keeping the default batching behavior for other reactions.
Constraints: In MobX 6 reactions are scheduled as micro‑tasks by default, and all changes made inside an action are batched so that reactions run only after the action finishes. Disabling the global reaction scheduler forces synchronous execution for every reaction, which may break existing assumptions and affect performance.
Uncertainty: The core team has discussed allowing certain observables or reactions to opt‑in to immediate notification without turning off the scheduler globally, but no official API exists yet.
Questions:
- Can MobX be configured to run specific reactions synchronously while leaving the global micro‑task scheduler unchanged?
- Is there a way to annotate an observable or reaction (e.g., via options) to opt‑in to immediate notification inside actions?
- What are the predictability and performance trade‑offs of permitting synchronous reactions for a subset of observables?