Background
A browser-side shared-state update received from the node side emits the same write back. If that write arrives after its key is deleted and recreated, the replacement accepts the old synchronization ID and loses its new value.
Changes
Suppress only the received state object and synchronization ID while applying a snapshot or patch. Restore the previous receive context after synchronous callbacks. Local writes, nested callback writes and writes to another key with the same ID still propagate.
The production change adds 20 lines and removes 3 in one file. No public API or wire-format change.
Reproduction
The added tests use native RpcFunctionsHostImpl and createRpcSharedStateClientHost. Only outgoing I/O is queued.
- Publish
{ count: 5 } from the node side and deliver its update to the browser side. Hold the resulting outgoing write.
- Delete the state on both sides and recreate its key as
{ count: 6 }. Read the replacement normally.
- Release the held write. Unchanged code replaces 6 with 5. This fix preserves 6 for both snapshots and patches.
In a disposable checkout of this branch, install the locked dependencies with pnpm install --frozen-lockfile. Run the same tests with the production file restored to the unchanged base, then with the fix:
git restore --source=72d917d5a57837b748bc9c950a0216049d13363e -- packages/devframe/src/client/rpc-shared-state.ts
pnpm exec vitest run --project devframe packages/devframe/src/client/rpc-shared-state-echo.test.ts
# Two failures: expected { count: 6 }, received { count: 5 }.
git restore --source=HEAD -- packages/devframe/src/client/rpc-shared-state.ts
pnpm exec vitest run --project devframe packages/devframe/src/client/rpc-shared-state-echo.test.ts
# All three cases pass.
Verification
- Reproduced both failures on unchanged main
72d917d5, using native source only.
- Four focused shared-state/RPC test files pass: 18 tests, including all three regressions.
- ESLint on both changed files,
devframe TypeScript checks and the devframe package build pass.
Local source checks use a cached dependency graph with Vitest 5.0.1, TypeScript 6.0.3 and Vite 8.3.1. Full CI also passes with the current lockfile: lint, Ubuntu/Windows Node 22/24/26 test jobs, end-to-end tests and Bun/Deno runtime checks.