Skip to content

fix: make serialize:true scope id track reactive hook-time path params - #150

Merged
zedrdave merged 2 commits into
mainfrom
fix/serialize-scope-reactivity
Jul 18, 2026
Merged

fix: make serialize:true scope id track reactive hook-time path params#150
zedrdave merged 2 commits into
mainfrom
fix/serialize-scope-reactivity

Conversation

@zedrdave

Copy link
Copy Markdown
Member

Summary

Fixes a reactivity defect in the serialize option shipped in 0.23.0 (#149): the derived scope id was computed once at hook setup, so reactive hook-time path params that changed afterwards left the hook with a stale scope id.

The bug

  • serializeScope was a plain object built from resolvedPath.value at setup.
  • With a ref/getter path param (e.g. a route param), the mutationFn used the new resolved path while the scope kept the old id.
  • Two hooks converging on the same resource after a param change held different scope ids and ran concurrently: the exact last-write-wins race serialize documents preventing.

The fix

  • serializeScope is now a computed deriving the id from hook-time params only (resolvePath(config.path, toValue(resolvedPathParamsInput))). vue-query wraps mutation options in a computed and unrefs them per dispatch (cloneDeepUnref), and query-core resolves scope.id per mutation via scopeFor, so each mutate() sees the current id.
  • Mutate-time extraPathParams are deliberately excluded: deferred params keep the documented template-fallback behaviour, and one call's params cannot leak into the next call's scope.

Risk assessment

  • Low risk: change is confined to scope-id derivation; string scopes, explicit-scope precedence, warning behaviour, and deferred-param fallback are untouched (all covered by existing tests, 9/9 passing).
  • Regression test added (hook with ref param converging on another hook's resource must queue). Verified to fail against the 0.23.0 implementation and pass with the fix.

Release

  • Version 0.23.0 → 0.23.1 (patch), CHANGELOG entry, README note on scope-id reactivity.

Validation

  • npm run check
  • npx vitest run tests/unit/mutation-serialize.test.ts → 9/9 ✅

The derived scope id was frozen at hook setup from resolvedPath.value.
With reactive hook-time path params (ref/getter), a hook whose param
changed kept the stale scope id, so two hooks converging on the same
resource could run concurrently: exactly the last-write-wins race that
serialize documents preventing.

The scope is now a computed derived from hook-time params only
(vue-query unrefs it per dispatch via cloneDeepUnref). Mutate-time
extraPathParams are deliberately excluded so deferred params keep the
documented template-fallback behaviour and never leak between calls.

Regression test verified to fail against the previous implementation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a reactivity defect in the mutation serialize: true option so the derived TanStack Query scope.id stays in sync when hook-time path params are reactive (e.g. route params). This prevents “converging” hooks from accidentally running concurrently under different (stale) scope ids.

Changes:

  • Make the derived serialization scope id reactive (computed) and based only on hook-time path params (excluding mutate-time extraPathParams).
  • Add a regression test covering reactive hook-time path param changes and subsequent queuing behavior.
  • Patch release housekeeping: version bump, CHANGELOG entry, and README clarification about reactive scope ids.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/openapi-mutation.ts Reworks serializescope.id derivation to track reactive hook-time params and avoid leaking mutate-time params into subsequent scope ids.
tests/unit/mutation-serialize.test.ts Adds regression test ensuring two hooks converge on the same resource and properly serialize after a reactive param change.
README.md Documents that serialize: true scope ids are reactive when hook-time params are refs/getters.
package.json Version bump to 0.23.1.
package-lock.json Lockfile version bump alignment to 0.23.1.
CHANGELOG.md Adds 0.23.1 entry describing the fix.

Comment thread src/openapi-mutation.ts
…lers

serialize is typed as plain boolean | string, but untyped JS callers
could pass a ref/getter and get silently wrong behaviour (Ref(false)
truthy -> enabled, Ref('group') non-string -> template scope id).
Unwrap with toValue() before the enable check and scope-id derivation.
@zedrdave
zedrdave merged commit bfd41f3 into main Jul 18, 2026
3 checks passed
@zedrdave
zedrdave deleted the fix/serialize-scope-reactivity branch July 18, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants