perf(chat): use content-visibility for off-screen messages#599
Open
HUQIANTAO wants to merge 1 commit into
Open
perf(chat): use content-visibility for off-screen messages#599HUQIANTAO wants to merge 1 commit into
HUQIANTAO wants to merge 1 commit into
Conversation
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.
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The message list renders up to 300 messages (
MAX_MESSAGES_IN_MEMORY) simultaneously via a plain.map()call. EachMessageItemincludes 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: autoto 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 elementscontain-intrinsic-block-size: 80px— provides a height estimate so scroll height is preserved without renderingThe 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-bottomanchor system.Messages within the last 50 (the typical viewport + buffer) are always rendered eagerly, ensuring no visual regression for the active conversation area.