Skip to content

fix(shared-state): avoid echoing received updates - #422

Draft
dvcolomban wants to merge 1 commit into
devframes:mainfrom
dvcolomban:dvcol/shared-state-echo
Draft

dvcolomban wants to merge 1 commit into
devframes:mainfrom
dvcolomban:dvcol/shared-state-echo

Conversation

@dvcolomban

@dvcolomban dvcolomban commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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.

  1. Publish { count: 5 } from the node side and deliver its update to the browser side. Hold the resulting outgoing write.
  2. Delete the state on both sides and recreate its key as { count: 6 }. Read the replacement normally.
  3. 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.

@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
devframe Skipped Skipped Oct 2, 2026 8:46am UTC

This branch was previously deployed

1 inactive deployment
Preview — de9c518f Deployed Oct 2, 2026 by vercel[bot]
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.

1 participant