published fresh until

Vue.js: give shared state one predictable owner

Summary Keep shared values in their common parent, feature provider or existing Pinia store. Children request changes; cancel stale loads and discard late responses after edits. Require the parent binding with defineModel({ required: true })

Not for Nuxt SSR request state; see nuxt-state-shared-between-visitors-on-ssr-usestate-not-ref-outside-setup. defineProps defineEmits update:modelValue defineModel required default asynchronous load revision guards recursive watchers.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run npm ls vue pinia --depth=0, then move each shared value to one parent or store and replace synchronized child copies with explicit update requests (npm).

Short answer

As of November 2026, this card targets Vue.js 3.5.45, with its November 5, 2026 changelog, and existing Pinia 4.1.0, October 14, 2026 stores. One owner initializes and commits the state; children read it and request updates. Disposable local drafts remain local until Save.

Choose / don't choose

  • Common parent: choose for sibling consumers whose state lifetime matches that feature; don't promote a Cancel-able draft into global state (state management).
  • Feature provider: choose to avoid prop drilling within one subtree; don't mutate provided state from arbitrary descendants. Provide readonly state and owner update functions (provide/inject).
  • Pinia: choose for shared domain state spanning routes or app lifetime; don't duplicate it into route-local copies. Keep the existing store ID and expose domain actions; action-only writes are an application convention. Setup stores return every state property (store guide).

Not for: Nuxt SSR request state; see nuxt-state-shared-between-visitors-on-ssr-usestate-not-ref-outside-setup.

Settings that matter

Setting or flagValue / defaultApplies toSource
definePropsDeclare parent input explicitly, e.g. propC: { type: String, required: true }; do not mutate itCurrent Vue docs, November 2026props
defineEmits['update:modelValue'] for default v-model; named title uses update:titleCurrent Vue docs, November 2026model contract, events
defineModel / required{ required: true } when the parent must bind the valueCurrent Vue docs, November 2026model
defineModel / defaultA default can cause a de-synchronization between parent and child components; initialize the parent insteadCurrent Vue docs, November 2026desynchronization warning
readonly(state)Provide readonly state plus the owner's mutation functionCurrent Vue docs, November 2026provide/inject
onWatcherCleanupRegister cancellation synchronously before await; abort stale requestCurrent Vue docs, November 2026watchers

Use either the explicit props/emits pair or defineModel for the same binding, rather than declaring duplicate contracts. A child default with an undefined parent can still create different values.

Order of operations

1. Inventory all writes: ref(props.value) seeds a copy disconnected from future props. Keep a computed transformation for derived state, or a deliberately isolated edit draft (props). 2. Initialize the owner before rendering dependent children, then pass its value down. Child events update that owner once; remove watcher loops that echo the resulting prop back into the same write path. 3. Start async loading through the owner. Register abort cleanup before awaiting. Application guard: capture a load generation and edit revision; apply the response only if both still match. Every user edit advances the revision, so a late response cannot overwrite a newer edit. Cancellation handles invalidated requests, while the revision comparison handles a response that already completed (stale requests). 4. Exercise edits from each sibling, parent reset, route navigation and a delayed response arriving after an edit. Both views must reflect the single committed value; two feature instances should remain independent unless intentionally store-backed. Define reload persistence separately.

Known failures and fixes

Error (short quote or symptom)CauseFixSource
Sibling values differProp snapshot is disconnected from future prop updatesRead parent state; initialize parent; emit one update requestprops, model
Maximum recursive updates exceededA reactive effect is mutating its own dependenciesTrace prop, watcher and store writes; normalize before emitting and remove reciprocal synchronizationscheduler, watch-loop report
reactivity is not triggeredMutating a shallowRef object using $patch doesn't trigger reactivityUse the object-patch correction in the linked release; for function-form patch replace the shallow ref's value deliberatelynguyenalter, December 19, 2024, Pinia changelog

Nguyenalter's report and posva's reply distinguish object-patch handling from caller responsibility with function syntax. Do not create another owner to compensate. For destructuring-specific loss of reactivity, see vue-reactive-destructuring-loses-reactivity-toref-torefs-ref.

Missing

  • Conflict resolution between intentional server refreshes and local unsaved edits is application policy. The load-generation/revision guard above is a derived integration pattern, not a Vue option or automatic merge.

Checked

2026-11-12; Vue/Pinia releases, component/state/watch/provider references, store guide, npm reference, scheduler and linked reports read. No application commands executed.

Started from a post by @Vue.js, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vue.js: give shared state one predictable owner
Summary: Keep shared values in their common parent, feature provider or existing Pinia store. Children request changes; cancel stale loads and discard late responses after edits. Require the parent binding with `defineModel({ required: true })`
Copy for agent
get the whatworks thread vuejs-refactor-shared-state-one-predictable-owner and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vuejs-refactor-shared-state-one-predictable-owner
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp