Skip to content

Chat: memoise item views so a streamed text delta re-renders only the last item #924

Open

Description

@smart-ssh-planner

Goal

A long chat stays responsive while an answer streams: each text delta re-renders only the item it changes, not every earlier item with its Markdown.

Context

On develop the frontend uses no React.memo at all. ChatPanel.tsx (:676–684) copies the whole items array on every chat-text-delta, and items.map (:1476) renders every ChatItemView, including react-markdown for each assistant message. After the chat panel series (#832–#847) the item views live in src/components/chat/ and the transcript reducer keeps the object identity of unchanged items.

Memoising was not safe before: DocumentCard reads the document-action registry with listDocumentActions() during render, and extension contributions registered later only appeared because the whole chat re-rendered. The reactive registry (#884) removes that dependency.

Requirements

  • ChatItemView (and AssistantMessageView/DocumentCard if they are rendered separately) is wrapped in React.memo; the props passed from the panel are stable for unchanged items (callbacks via useCallback or a stable dispatch, no inline objects).
  • DocumentCard reads document actions through the reactive registry (useSyncExternalStore subscription), so a document action registered or removed after the card was rendered still appears or disappears.
  • No visible behaviour change.

Acceptance Criteria

  • Test with the React Profiler (or a render counter in a test-only wrapper): a chat with 200 items receives 10 text deltas; only the last item re-renders per delta.
  • Test: a document action registered after a document card is shown appears on that card without any other state change; removing it makes it disappear.
  • Existing ChatPanel*.test.tsx and src/components/chat/* tests pass; their count does not decrease.
  • npm run lint, npx vitest run, npm run build and npm run test:e2e pass.

Technical Notes

  • Frontend only; no filter, risk, redaction or credential logic. The confirmation card of a proposed action must re-render when its decision or risk assessment changes (covered by existing tests).
  • New code comments in English.

Spec impact: none

Related Work

Activity

  1. added this to the 0.8.0 milestone on Oct 26, 2026
  2. 21 remaining items

  3. marked this as blocking 15 issues on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    frontendFrontend (React/TypeScript)

    Type

    Fields

    Priority

    P3 - Low

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions