:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
ChatX Thread Rebuild — Build Spec
Status: in progress. Source of decisions: grilling session 2026-06-27.
Thesis
Replace the virtualized thread (ConversationView + VirtualizedList) with shadcn
Base-UI chat primitives, renamed ChatX. Non-virtualized, content-visibility: auto,
minimal DOM, close to the shadcn examples. Primitives are built in quill; the app-side
thread is rebuilt in the code repo.
Provenance
The primitives are vendored from the shadcn base-mira registry:
https://ui.shadcn.com/r/styles/base-mira/{message-scroller,message,bubble,marker,attachment}.json- The scroll engine is the published headless package
@shadcn/react(MIT, exports./message-scroller). The styled file is a thin wrapper — same shape as quill'sBadgewrapping@base-ui/react. We take@shadcn/reactas a runtime dep of the quill primitives package and wrap it in quill conventions.
Where
- Primitives:
posthog/packages/quill/packages/primitives/src/chat-*.tsx(+ colocatedchat-*.css,chat-*.stories.tsx), exported fromindex.ts. Conventions:useRender/mergeProps/cva/data-quill/cnfrom./lib/utils, 4-space indent, single quotes. - App thread:
products/desktop/packages/ui— new<ChatThread>replacingConversationView. - Flow: build in quill → local-link → integrate → publish beta → bump catalog.
Primitives (v1 = four)
- ChatMessageScroller (Provider / Root / Viewport / Content / Item / Button + 3 hooks).
Thin wrap of
@shadcn/react/message-scroller. Non-virtualized.autoScroll,defaultScrollPosition="end",scrollPreviousItemPeek≈64,scrollAnchoron turn-start items. Imperative scroll state via data-attrs; no React state on scroll. - ChatMessage (Group / Avatar / Content / Header / Footer).
align="start|end". Avatar first-class, omitted in our render. - ChatBubble (Content / Reactions / Group). Assistant =
ghost(no bg, full-width); user = filled. - ChatMarker (Icon / Content) — the recursive one. Diverges from stock shadcn
Marker: when given a
body, renders as a Base-UI Collapsible — hover shows a chevronbg-fill-hover, click toggles, expanded renders the body. No body → flat status line (stock shadcn). UncontrolleddefaultOpen+ optionalopen/onOpenChange. Pairs withSpinner+ shimmer for live state.
Deferred: ChatAttachment (except trivial mention chips), BubbleReactions.
Mapping (app layer)
- User turn →
ChatMessage align="end"→ filledChatBubble→ text (+ mention chips). - Assistant turn →
ChatMessage align="start"→ghost ChatBubble→ bare markdown. - Single tool →
ChatMarkerwithbody= injected detail (<ReadContent/>,<EditDiff/>— reused existing renderers; primitive is chrome-only). - Tool group (completed turn) → summary
ChatMarker("Read 3 files · Edited 1") whosebody= the per-tool childChatMarkers. - Status / thought / error / compact / cancelled →
ChatMarker(default/border/separator). - MCP app iframes → top-level rows, outside grouping, IntersectionObserver mount/unmount (no state preservation — acceptable).
Grouping / collapse
mode={all|partial|none}on<ChatThread>(app), not the primitive. App maps mode → per-markerdefaultOpen:none→true,all→false,partial→isActiveTurn.- Live→complete: live turn renders expanded markers (Spinner/shimmer); on completion
the grouper swaps row identity → one collapsed summary marker mounts fresh. Keep
createIncrementalThreadGrouper. No controlled-state flipping.
Escape hatch (heavy rows)
Heavy rows opt into IntersectionObserver mount/unmount + placeholder. Off-screen MCP apps
unmount. content-visibility: auto saves paint, not React mount cost — this caps live
iframe processes.
Anchoring / streaming
- Anchor = user message when present, else turn's first assistant row;
scrollAnchoron those items only. content-visibility: auto+ tunedcontain-intrinsic-sizeper row type. Accept-and-tune for v1; leave a seam for a measured-size cache if the 1000-turn stress shows drift.
Build order
- Scroller + dummy rows + 1000-turn stress story (prove thesis).
ChatMarker(all variants / fill levels).ChatMessage+ChatBubble.- Link →
<ChatThread>(parse→group→primitives,mode, MCP mounting) behind existing composer. - Stress real thread, tune sizes.
Each primitive ships *.stories.tsx with shadcn-shaped fixtures.
Kept untouched
Existing composer; event→item parse; optimistic merge; incremental grouper; tool detail renderers.