PR #8292 review: live presence and cursors on pages

Summary

The PR adds live presence to pages. Header avatars show who else is viewing, and each remote viewer's pointer appears with a name label. It works on web, the public page view, desktop and mobile. Everything goes through the existing PageHub Durable Object and the frame's storage socket. A new unauthenticated guest-ticket route lets anonymous visitors of pages shared with everyone join as presence-only "Guest" viewers. The socket now reconnects with backoff, sends a heartbeat that the DO answers with an auto-response, and an alarm sweep closes sockets that stop answering.

Verdict

Minor issues The design is sound and fits the existing hub. I found no blocking bug, and the realtime path works end to end in a browser harness. Before merge, someone should decide whether anonymous guests may see members' names, avatars and user ids. A few smaller issues follow.

Findings

Medium · privacy / product decision

apps/realtime/src/page-hub.ts:534-555 (announce). Guests get the same roster as members: each member's real userId, full name and image URL. On a public page, any anonymous visitor can open the socket and read the names and internal user UUIDs of every org member who has the page open. Members are not told this. The PR lists it under known limitations, but I could not find a decision on it.

Fix: when the recipient is a guest, redact members to { id, userId: "member:"+connectionId, name: "", image: null }, which renders as "Member". At minimum, do not send real user UUIDs to guests. If showing names is intended, say so in the share dialog's "everyone" copy.

Medium · abuse

apps/realtime/src/index.ts:132 and apps/realtime/src/page-hub.ts:233-241. The guest-ticket route needs no auth and has no rate limit. The DO refuses the 21st guest with 4429. One script that holds 20 guest sockets on a public page (pinging every 25 s keeps them past the sweep) locks every real guest out of presence on that page. Pages still load, so the impact is limited to presence.

Fix: when the cap is reached, evict the oldest or idle guest instead of refusing the new one. Also cap guests per client IP (CF-Connecting-IP stored in the ticket), and add the Cloudflare rate-limit rule the PR suggests before merge, not after.

Low · reconnect

packages/shared/src/page-storage-runtime.ts:215. Only 4403 stops retries. A guest refused with 4429 "full" keeps redialing every 30 s (after the backoff) for as long as the tab is open. Each redial mints a ticket and wakes the DO, which makes the finding above worse.

Fix: treat 4429 as refused, or give it a long fixed delay (for example 5 min).

Low · UX

packages/shared/src/page-presence.ts:47-62. presenceColor hashes into 8 colours, so two viewers share a colour 12.5% of the time, and some pair of three viewers does 34% of the time. In my first harness run all three people (Ada, Grace, Guest) came out the same green (screenshot below). Then the colour no longer tells cursors apart, and "Grace" and "Guest" also share the initial "G" in the header.

Fix: let the DO give each connection a palette slot that no current connection uses, and send it in the roster. Every viewer then sees the same colour, and colours collide only after 8 people.

Low · desktop pinch-zoom (by reading)

packages/ui/src/components/PageComments/components/PagePresence/PagePresence.tsx:80 reads viewportRef.current during render. A viewport-zoom message updates the ref but does not re-render PagePresence. The storage runtime sees no scroll, because the zoom is a transform on the iframe. So after a pinch-zoom or pan in the desktop viewer, remote cursors stay in the wrong place until the next cursor message. I did not run this on desktop.

Fix: keep the viewport in state (or a small store) that PagePresence subscribes to, or pass a version counter that PageCommentsView bumps on viewport-zoom.

Low · state

packages/ui/src/components/PageComments/components/PagePresence/PagePresence.tsx:74-77 and stores/pagePresenceStore/pagePresenceStore.ts:14-18. The store holds one list per pageId, and unmount clears it. If two views of the same page are mounted, for example two page panes in one workspace, closing one clears the other's header avatars until the next presence message comes in.

Fix: key the store by component instance and merge the lists per page, or count references and clear only when the last view unmounts.

Low · cost (question)

apps/realtime/src/page-hub.ts:482-501. The sweep alarm runs every 30 s for as long as any socket is open, so a hibernated hub wakes 2,880 times a day per page left open in a tab. The auto-response keeps pings free, but the alarm brings the cost back. It is probably cheap, but please check it against the expected number of open pages. A 60 s sweep with a 120 s silence limit halves the wakes.

Repo rules: structure follows the co-location rules (PublicPageFrame under PublicPageView/components, stores and nested components in their own folders). There are no tRPC changes. New strings are translated in all 16 locales. Comments are minimal. The new tests use injected short timers, not real waits.

Evidence

Setup: a browser harness at PR head 7caf9590. It runs the PR's apps/realtime under wrangler dev with a public-page manifest seeded in R2, a frame server at http://<pageId>.frame.usercontent.localhost:9999 that serves a page with the PR's real pageStorageRuntimeSource(), and a host page that bundles the PR's real PageFrame, PagePresence, PageViewers and usePageStorageConnect with the real pageGuestSocketUrl. Members get tickets from the real ticket route with locally signed JWTs. Headless Chrome 153 runs three windows: Ada (1280 px), Grace (860 px) and an anonymous guest (1100 px). The theme CSS is not loaded, so tooltip and header styling are not the real app's. Lingui macros are shimmed to return the English text.

Presence and cursors (web components plus realtime)

Ada's view: Grace's and the guest's cursors with name labels; header avatars for Grace and Guest; Ada is not listed.
Grace's narrower window: Ada's pointer is on the "Hiring" card here too. Measured: the cursor tip is inside the card's box.
The anonymous guest sees both members by full name. This is finding 1.
Grace scrolls 150 px: Ada's cursor moves up with the card (card y 189→39, cursor y 221→71).
Hovering a header avatar shows the viewer's name (unstyled here, without the app's theme CSS).
Recording of Grace's window for the whole run: cursors appear and move, the scroll, the worker restart, and the un-share.

Reconnect after a realtime restart

Realtime worker killed: presence and cursors clear in Ada's view.
Worker restarted: the roster came back about 3 s later with no reload, and cursors resumed.

Un-sharing closes guests

The page was set to "org" and manifest-changed was sent. Ada's roster drops the guest and keeps Grace.
The guest's view after the un-share: no viewers and no cursors (socket closed with 4403, no redial).

Colour collision (finding 4)

First run, with other test user ids: Ada, Grace and the guest all hashed to the same green.

Silent-socket sweep (CLI)

A member socket that sent one ping and then went quiet was closed with 4408 after 89 s. A second member that kept pinging stayed open and got a roster without the silent one. This is in line with the 75 s silence limit plus up to 30 s for the next sweep.

Surfaces I could not run

Questions for the author

Test / CI notes

WhatResult (at 7caf9590)
GitHub CIAll checks green: Lint, Typecheck, Test, Sherif, Page storage integration, Build CLI, previews deployed.
bun test --isolate on page-presence, page-storage-runtime, page-storage-access, usercontent/ticket48 pass, 0 fail
apps/realtime bun run test:integration (wrangler dev)All checks pass, including the 14 new presence/guest checks
Browser harness (above)Presence, cursors across widths, scroll-follow, restart recovery (3 s), un-share all as described
Silent-socket sweepEvicted with 4408 after 89 s; live socket kept
Desktop, full web route, iOSNot run (see above)

The harness files were temporary and not committed: packages/ui/src/__pr_harness__/ and apps/realtime/scripts/pr-harness.ts. I removed them after the run.