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
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.
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.
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).
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.
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.
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.
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)





Reconnect after a realtime restart


Un-sharing closes guests

manifest-changed was sent. Ada's roster drops the guest and keeps Grace.
Colour collision (finding 4)

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
- Desktop app (
PageDetailViewandPagePaneHeaderExtrasheader slots,PageViewer). The workspace's dev stack was up (Electron, web :3000, API :3001, realtime :3018), but the usercontent worker was not running. I started it. The local usercontent and realtime workers read their own Miniflare R2, not the MinIO bucket the local API publishes to, so no locally published page reaches them. The PR lists this as a known limitation. The local DB connection string also failed authentication. I stopped there. Not verified. - Full Next.js public page route (
/page/[slug]withPublicPageViewandPublicPageFrame): same blocker. The harness used the same components and guest-ticket helper, but not the Next.js route orPageHeaderBar. - iOS app (
PageFramebridge,injectedJavaScriptBeforeContentLoadedhost flag, nativePagePresence): this needs an Expo dev build on Limrun and the same page-serving stack. Not attempted. The open question from the PR still stands: does the host flag land before the runtime in the page head runs?
Questions for the author
- Should anonymous guests see members' full names, avatars and user ids on public pages? Was this decided with product, or is it a side effect of reusing the roster?
- Will the Cloudflare rate-limit rule on
/v2/page/*/storage/guest-ticketbe in place before the realtime deploy? Would you take "evict the oldest guest" instead of refusing at 20? - Is a 30 s alarm per open page acceptable cost-wise at current page traffic?
- Signed-in users from other orgs show as "Guest" on public pages, but their own header shows members by name. Is that asymmetry intended?
Test / CI notes
| What | Result (at 7caf9590) |
|---|---|
| GitHub CI | All 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/ticket | 48 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 sweep | Evicted with 4408 after 89 s; live socket kept |
| Desktop, full web route, iOS | Not 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.