Tracker reactivity compatibility boundary with React and Vue integration
0 reputation · 05 Mar 2020, 01:49 UTC
0 reputation · 05 Mar 2020, 01:49 UTC
The client-side reactivity model in Meteor is built on Tracker and DDP. The documented transition from Blaze-based reactivity to integration with React and Vue introduces a compatibility boundary for how state is observed and synchronized.
A design goal is to make the user-facing workflow more accessible by providing clearer visibility into DDP subscription lifecycles and Tracker dependencies. The current model can obscure why a component does not refresh, and global reactive usage raises concerns about observer cleanup on component unmount and DDP overhead with many active subscriptions.
The behavior of allow rules with deeply nested reactive objects remains an unresolved decision point, as dependencies may not be explicitly tracked.
What ownership model is intended for Tracker autorun cleanup in modern framework components? How should subscription readiness be surfaced to framework state without duplicate observers? Is there a documented compatibility boundary for nested reactive updates under allow rules?
34775 reputation · 05 Mar 2020, 09:09 UTC
In modern framework integrations, the ownership of Tracker.autorun cleanup belongs to the component's unmount lifecycle. Because Tracker operates independently of the React or Vue virtual DOM, it will continue to execute and trigger state updates even after a component is destroyed unless explicitly stopped.
Tracker.autorun must be called within the cleanup function of a useEffect hook.onUnmounted lifecycle hook.// Example React Pattern
useEffect(() => {
const stop = Tracker.autorun(() => {
const data = Collection.find().fetch();
setState(data);
});
return () => stop();
}, []);
To surface subscription readiness without creating duplicate observers, the recommended approach is to treat the subscription status as a piece of framework-level state, driven by a single Tracker boundary.
Rather than wrapping every component in a separate observer, use a reactive wrapper or custom hook that monitors Meteor.subscription().ready(). This allows the framework to render a loading state until the DDP synchronization is complete, ensuring that subsequent data fetches are performed against a populated local cache.
There is no documented, automatic compatibility boundary for deeply nested reactive updates under allow rules or general Tracker observations. Tracker relies on dependency tracking via getters. If a nested property is modified without changing the reference of the parent object or triggering a reactive variable, Tracker may not detect the change.
Confirmed Behavior:
ReactiveDict, ReactiveVar, or explicitly trigger a re-run by updating a tracked dependency.autorun callback ceases to execute.stop messages are sent when the component managing the subscription unmounts.ReactiveVar trigger.Diagnostic Note: To refine the recommendation for nested updates, please specify if you are using minimongo collections or custom client-side state objects.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.