File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 14631463 top: messagesContainerElement .scrollHeight ,
14641464 behavior
14651465 });
1466+
1467+ // content-visibility: auto causes the initial scrollHeight to be based on
1468+ // estimated sizes (contain-intrinsic-size). After we scroll, previously
1469+ // off-screen messages become visible and the browser resolves their actual
1470+ // heights, which shifts scrollHeight. Re-layouts can cascade across frames
1471+ // (new sizes reveal more content, triggering further size resolution), so
1472+ // we re-scroll across two animation frames to land at the true bottom.
1473+ requestAnimationFrame (() => {
1474+ if (messagesContainerElement ) {
1475+ messagesContainerElement .scrollTo ({
1476+ top: messagesContainerElement .scrollHeight ,
1477+ behavior
1478+ });
1479+ requestAnimationFrame (() => {
1480+ if (messagesContainerElement ) {
1481+ messagesContainerElement .scrollTo ({
1482+ top: messagesContainerElement .scrollHeight ,
1483+ behavior
1484+ });
1485+ }
1486+ });
1487+ }
1488+ });
14661489 }
14671490 };
14681491
Original file line number Diff line number Diff line change 140140
141141 const scrollToBottom = () => {
142142 const element = document .getElementById (' messages-container' );
143- element .scrollTop = element .scrollHeight ;
143+ if (element ) {
144+ element .scrollTop = element .scrollHeight ;
145+
146+ // Follow-up scroll to account for content-visibility: auto re-layouts
147+ requestAnimationFrame (() => {
148+ if (element ) {
149+ element .scrollTop = element .scrollHeight ;
150+ }
151+ });
152+ }
144153 };
145154
146155 export const scrollToTop = async () => {
You can’t perform that action at this time.
0 commit comments