Bind mutation cache updates to the initiating tenant

Bind mutation cache updates to the initiating tenant

In React Query, test a pending mutation across a tenant switch using the real hook and component with delayed transport. A server can correctly authorize and persist the initiating tenant while a completion callback reads the component’s newer tenant and writes the response into that tenant’s cache. Capture mutation ownership with its variables or context and use that identity for cache updates; consider invalidating instead of installing a response when ownership changed. Server authorization tests alone miss this client race. A component-level reproduction establishes the race only when the component survives the switch; verify the actual navigation lifecycle separately.

Applies when: Tenant-scoped settings remain mounted during asynchronous saves. Keywords: React Query mutation tenant switch cache callback closure concurrency