Skip to content

perf(chat): use content-visibility for off-screen messages#599

Open
HUQIANTAO wants to merge 1 commit into
op7418:mainfrom
HUQIANTAO:perf/message-list-virtualization
Open

perf(chat): use content-visibility for off-screen messages#599
HUQIANTAO wants to merge 1 commit into
op7418:mainfrom
HUQIANTAO:perf/message-list-virtualization

Conversation

@HUQIANTAO
Copy link
Copy Markdown

Problem

The message list renders up to 300 messages (MAX_MESSAGES_IN_MEMORY) simultaneously via a plain .map() call. Each MessageItem includes markdown parsing, Shiki code highlighting, tool call groups, and widget iframes — creating significant DOM node count and paint cost even for messages far off-screen.

Fix

Apply CSS content-visibility: auto to message wrappers older than the last 50 messages. This is a browser-native rendering optimization:

  • content-visibility: auto — tells the browser to skip layout and paint for off-screen elements
  • contain-intrinsic-block-size: 80px — provides a height estimate so scroll height is preserved without rendering

The browser natively manages which messages to render based on viewport visibility, with zero JavaScript overhead. This is a pure CSS optimization — no changes to scroll behavior, message ordering, or the existing use-stick-to-bottom anchor system.

Messages within the last 50 (the typical viewport + buffer) are always rendered eagerly, ensuring no visual regression for the active conversation area.

The message list renders up to 300 messages (MAX_MESSAGES_IN_MEMORY)
simultaneously. Each MessageItem includes markdown parsing, code
highlighting (Shiki), tool call groups, and widget iframes — creating
significant DOM node count and paint cost even for off-screen messages.

Add CSS content-visibility:auto to messages older than the last 50.
This tells the browser to skip layout and paint for off-screen content
while preserving scroll height via contain-intrinsic-block-size. The
browser natively manages which messages to render based on viewport
visibility, with zero JavaScript overhead.

This is a pure CSS optimization — no changes to scroll behavior,
message ordering, or the existing use-stick-to-bottom anchor system.
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 4, 2026

Someone is attempting to deploy a commit to the op7418's projects Team on Vercel.

A member of the Team first needs to authorize it.

@HUQIANTAO HUQIANTAO changed the base branch from worktree-product-refactor-research to main June 5, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant