Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): stop remounting markdown on every activity delta #9306

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/9306/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Problem

Selecting assistant text on a working thread and clicking "Cite" was flaky: the selection would walk up one block at a time every ~250ms and the toolbar vanished within about a second. Idle threads were fine.

The selection endpoints were being destroyed. MessagesTimeline's sharedState memo built a fresh threadRef via parseScopedThreadKey(routeThreadKey) on every recompute, and it recomputes on every activity delta (agentPanelModel derives from threadActivities). ChatMarkdown keys its react-markdown components map on threadRef, and react-markdown uses those functions as React element types, so a new identity remounted every <p>/<pre>/<code> in every visible assistant message. Chrome repairs a selection whose nodes were removed to the nearest boundary, hence the one-block-per-tick walk.

This predates the cite feature; it was already re-creating shiki blocks and chips on every delta.

Fix

Reuse the already-memoized citationThreadRef so ChatMarkdown's props stay referentially stable and its memo bails out on activity ticks.

Verified with vp lint, apps/web typecheck, and the MessagesTimeline tests (114 passing).


Claude Fable 5 via Claude Code

🤖 Generated with Claude Code


Note

Low Risk Single-line behavioral fix reusing an existing memoized value; no API or security changes, with tests already noted as passing.

Overview Fixes flaky assistant text selection and Cite on working threads by keeping threadRef referentially stable in timeline row shared context.

MessagesTimeline no longer calls parseScopedThreadKey(routeThreadKey) inside the sharedState memo (which recomputes on each activity tick via agentPanelModel). It now passes the existing memoized citationThreadRef into context so ChatMarkdown props stay stable, react-markdown does not treat new component types on every delta, and assistant markdown blocks are not remounted while the agent is active.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ff3883a3febac37996dc36510ddf2e49239c6b9e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Stop remounting markdown in MessagesTimeline on activity delta

The shared timeline state now uses the existing citationThreadRef instead of building a new object from parseScopedThreadKey(routeThreadKey). citationThreadRef is added to the useMemo dependency list so its stable reference carries across activity-driven recomputations. This keeps ChatMarkdown's component map from being recreated on every update.

Macroscope summarized ff3883a.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.3 KiB13.4 KiB+161 B (+1.2%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB0 B (0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.4 KiB6.6 KiB+161 B (+2.5%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.6 KiB57.0 KiB+1.4 KiB (+2.6%)66.4 KiB✅
      CodexLive turn messages10100 (0.0%)21✅
      ClaudeTotal thread wire13.5 KiB13.5 KiB+10 B (+0.1%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB−3 B (−0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.6 KiB+13 B (+0.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.8 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages10100 (0.0%)21✅

      Baseline: ef6cc0b · PR result: ff3883a · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. Approvability

      Verdict: Approved at ff3883a

      Macroscope's review found this PR approvable — This is a narrowly scoped rendering fix that preserves the existing thread identity while preventing markdown components from remounting during activity updates. It does not introduce new capabilities, schema changes, configuration changes, or sensitive-path modifications.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge merged this355fbd9

    5. juliusmarminge closed this

Sign in to join this conversation.