Skip to content

Support primitive page data updates - #303

Open
spencerc99 wants to merge 2 commits into
mainfrom
cx/page-data-primitive-roots
Open

Support primitive page data updates#303
spencerc99 wants to merge 2 commits into
mainfrom
cx/page-data-primitive-roots

Conversation

@spencerc99

@spencerc99 spencerc99 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Support direct replacement and functional updates for primitive page-data roots.
  • Read primitive functional updates from the live page-data store after remote Yjs replacements.
  • Preserve object and array draft mutators, including terse returns such as d => d.count++.
  • Document the contract and add working visit-counter examples to both starters.

Root cause

Primitive values were held in the page-data map, but the existing replacement helper only mutated object and array proxies. Functional returns were ignored. The initial primitive implementation also retained a stale scalar in proxyByTagAndId after a peer replacement.

Regression coverage

A two-document Yjs test seeds B with cached 0, applies A's remote update to 1, verifies B reads 1, then verifies B's value => value + 1 writes 2.

PR #264 integration

#264 overlaps PageDataChannel.setData for server-gated writes. Keep this branch's root-replacement and PageDataSetter behavior, and derive its gated before snapshot from the same live primitive store value. Then mutate object drafts or use primitive updater returns before buildGatedWriteOps. The server already sends that value as a replace operation. I applied and type-checked that combined hunk against #264.

Validation

  • bun run build and bun run test in packages/playhtml: 364 tests passed
  • bun run build and bun run test in packages/react: 44 tests passed
  • Temporary Identity, authentication & permissions system #264 integration: packages/playhtml build and page-data suite passed

@pkg-pr-new

pkg-pr-new Bot commented Jul 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

bun add https://pkg.pr.new/@playhtml/common@303
bun add https://pkg.pr.new/playhtml@303
bun add https://pkg.pr.new/@playhtml/react@303

commit: f56fc3f

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 12, 2026

Copy link
Copy Markdown

Deploying playhtml with  Cloudflare Pages  Cloudflare Pages

Latest commit: f56fc3f
Status: ✅  Deploy successful!
Preview URL: https://72767ad4.playhtml.pages.dev
Branch Preview URL: https://cx-page-data-primitive-roots.playhtml.pages.dev

View logs

@spencerc99
spencerc99 marked this pull request as ready for review July 13, 2026 05:26
@spencerc99

Copy link
Copy Markdown
Owner Author

Code review

  • P2 packages/common/src/index.ts:399 makes nullable object channels lose contextual typing for functional updates. Because the conditional type distributes over unions, PageDataSetter<Item | null> becomes a union containing incompatible callback signatures for Item and null. In strict TypeScript, a realistic update such as channel.setData(value => value ?? { id: "first" }) now reports TS7006 because value is implicitly any; the previous setter signature contextually typed that parameter as the full Item | null union. Define the callback once over the full T (for example, a single (value: T) => T | void shape or overloads that preserve contextual typing) and add a declaration test for a nullable object channel.

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