Repository navigation
feat(Chat): add XDSChatLayout with fixed composer dock and container queries - #1249
Merged
Merged
Conversation
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsChat · View in Storybook · 🆕 XDSChatTokenizedText, XDSChatLayout
ProgressBar · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
force-pushed
the
navi/feat/chat-layout
branch
4 times, most recently
from
April 11, 2026 00:03
138986e to
113b6f5
Compare
cixzhang
marked this pull request as ready for review
April 11, 2026 02:10
added 21 commits
April 11, 2026 10:21
XDSChatLayout now provides a scroll container context that XDSChatMessageList picks up automatically. Auto-scroll, scroll-to-bottom, and new message detection all target the correct scrollable ancestor. - Add scrollRef prop to XDSChatLayout — delegates scrolling to a parent element or document body when the layout isn't the scroll container - Add XDSChatLayoutContext — passes scroll container ref to descendants - useAutoScroll accepts optional scrollContainerRef - XDSChatMessageList reads layout context and disables its own overflow when inside a layout (scroll container is the layout root) - Update Chat.doc.mjs with scrollRef prop docs and examples
…ories - Panel View now has streaming, triggers, attachments, tool calls — same features as Full AI Chat but in a 400×600 sidebar container - Replace inline empty state markup with XDSEmptyState in both ChatLayout and ChatMessageList stories
Without a minWidth, the progress bar container could shrink to zero inside flex parents (e.g. the composer header slot). 48px ensures the track is always visible.
XDSChatLayoutContext now provides dockHeight, which the message list uses to position the scroll-to-bottom button above the composer. No arbitrary values for consumers — the layout measures the dock and provides the offset automatically. Also: ProgressBar now spreads rest props (aria-describedby, etc).
XDSChatMessageList is now purely presentational — messages, density context, empty state, spacer, infinite scroll sentinel. No scroll behavior, no scroll button. XDSChatLayout owns all scroll concerns: - useAutoScroll for scroll-to-bottom and new message detection - ResizeObserver on the message content area (via contentRef in context) to detect height changes from new/streaming content - ScrollToBottomButton rendered above the composer dock - Scroll listener attached to the scroll container The layout context provides contentRef — the message list attaches it to its inner element so the layout can observe height changes. No effects on children, no callbacks — just measurement. useAutoScroll and ScrollToBottomButton remain exported for standalone composition without XDSChatLayout.
ResizeObserver on the content area now checks the message count against a ref. Only triggers onContentChange when messages are added — not when existing content resizes (tool call expand, drawer collapse, etc).
Replaces querySelectorAll count with a reference comparison on the last .xds-chat-message element. Faster (getElementsByClassName is a live collection, just grab the last one) and correctly ignores upward loads — prepending old messages doesn't change the last element.
…ayout Sticky doesn't work when content is shorter than the container. Absolute + bottom: 0 anchors to the layout root regardless of content height.
…fined children - Rename component + file + test + all story references - Re-export old name as deprecated alias for backwards compat - Guard against undefined children (fixes e.replace crash during streaming) - Fix MessageList test: scroll button now owned by Layout
- Remove hasAutoScroll/scrollThreshold from MessageList docs - Add hasAutoScroll/newMessagesLabel to Layout docs - Update MessageList descriptions across all doc variants - All three doc variants (main, zh, dense) now consistent
…ion from MessageList
Absolute positioning broke layout flow. Sticky works correctly when the message area has min-height: 100% — the dock always has content to stick against, even when messages are short.
added 20 commits
April 11, 2026 10:22
Callback ref fires synchronously when the message list registers its element — no effect timing issues. The ResizeObserver connects and disconnects inside the callback, managed via observerRef.
One observer instance watches both the root (for density breakpoints) and the content element (for new messages). Dispatches by checking entry.target. Reduces observer count from 2 to 1.
Root resizes when content grows. One ResizeObserver on root handles both density and new message detection. Removed contentRef from context, callback ref, and message list registration.
scrollRef.current was null when the scroll listener effect first ran. Track root mount via state so the effect re-runs once the element exists. Also calls scrollToBottom(false) when the listener attaches.
Callback ref fires during commit before layout is complete. requestAnimationFrame ensures content has rendered and scrollHeight is accurate before scrolling to bottom.
…ssage list) Root is the scroll container — it doesn't resize when messages grow, it scrolls. The message list inner div is what actually changes height. Two observers: - Root: density breakpoints (clientWidth) - Content: new message detection (last .xds-chat-message element) Message list registers its inner div via contentRef in context.
Two resize behaviors: - Last message changed → onContentChange (auto-scroll or 'new messages') - Same message growing (streaming) → scrollToBottomIfNearBottom (auto-scroll if near bottom, no 'new messages' flag) Added scrollToBottomIfNearBottom to useAutoScroll — scrolls only if near bottom, silently ignores if scrolled up.
…roll Instead of measuring distance from bottom on every scroll event to decide if we're 'near enough', use a binary lock: - Locked (default): auto-scroll follows content, streaming stays pinned - User scrolls up: unlock — auto-scroll stops, new messages flagged - User scrolls to bottom: re-lock — auto-scroll resumes Programmatic scrolls (our scrollToBottom calls) are flagged via isProgrammaticRef so they don't affect the lock state. The flag clears on the next animation frame. scrollToBottomIfLocked replaces scrollToBottomIfNearBottom — used for streaming content growth (same message getting taller).
scrollToBottom scrolls to bottom → scroll event fires → distance is 0 → re-locks. User scrolls up → distance > threshold → unlocks. No need to distinguish programmatic vs user scrolls.
…teners Wheel events scrolling down at the bottom were unlocking the scroll lock momentarily — enough for a content change to miss the lock and not auto-scroll. Now only deltaY < 0 (scroll up) unlocks. Also wired up wheel + touchmove listeners on the scroll container and separated handleUserScroll (unlock) from handleScroll (re-lock).
Wheel/touch sets userScrollingRef flag. handleScroll only unlocks if that flag is set AND the user has actually scrolled beyond scrollUpThreshold. Prevents micro-scrolls and trackpad noise from breaking the lock. Also: handleScroll no longer re-locks — only dismissNewMessages does. Auto-scroll on any height change (not just new messages). Removed bottomThreshold (unused).
scrollend fires once when scrolling settles. If isProgrammaticRef is set, it was our scroll → clear flag, stay locked. If not set, it was a user scroll → unlock immediately. No wheel/touch listeners needed. No distance threshold for unlock. Clean separation: programmatic scrolls never unlock, user scrolls always unlock.
…crollend User scroll → handleScroll → isProgrammatic is false → unlock immediately. Programmatic scroll → isProgrammatic is true → handleScroll skips unlock → scrollend clears flag.
- On scroll: if not programmatic AND past threshold → unlock - On scroll end: if at bottom → lock - Content grows + locked → scroll to bottom
If the user scrolls during a programmatic smooth scroll, the wheel/ touchstart handler clears isProgrammaticRef so the next handleScroll event can unlock normally. Prevents the auto-scroll from fighting the user back to the bottom.
Logs at every decision point: scrollToBottom, unlock, scrollend, user interrupt, content grew (locked/unlocked), new msg flagged. Filter console by '[auto-scroll]' in devtools.
cixzhang
force-pushed
the
navi/feat/chat-layout
branch
from
April 11, 2026 17:23
e113a57 to
b83410d
Compare
josephfarina
added a commit
that referenced
this pull request
Apr 12, 2026
…ix Chat @example Found during Night Watch doc review (2026-04-12). - Fix XDSChatTokenizedText @example: remove blank lines and JS comments inside code block (reintroduced by #1249) - Add xds-chat-layout theming target to Chat.doc.mjs (new in #1249) - Add missing Markdown props: contentWidth, contentAlign, sources, citationStyle (from #1289, #1290) - Add missing CodeBlock props: isCollapsible, collapsibleThreshold - Add Thumbnail theming section (xds-thumbnail target) - Add Thumbnail common props: xstyle, className, style, data-testid - Add Thumbnail docsZh and docsDense translations - Add Thumbnail accessibility section Co-authored-by: Navi <[email protected]>
4 tasks done
cixzhang
added a commit
that referenced
this pull request
Apr 26, 2026
…queries (#1249) * feat(Chat): add XDSChatLayout with fixed composer dock and container query density * feat(Chat): scrollRef prop on XDSChatLayout + auto-scroll delegation XDSChatLayout now provides a scroll container context that XDSChatMessageList picks up automatically. Auto-scroll, scroll-to-bottom, and new message detection all target the correct scrollable ancestor. - Add scrollRef prop to XDSChatLayout — delegates scrolling to a parent element or document body when the layout isn't the scroll container - Add XDSChatLayoutContext — passes scroll container ref to descendants - useAutoScroll accepts optional scrollContainerRef - XDSChatMessageList reads layout context and disables its own overflow when inside a layout (scroll container is the layout root) - Update Chat.doc.mjs with scrollRef prop docs and examples * fix(Chat): sticky composer dock in panel layouts * feat(Chat): full-featured Panel View story + XDSEmptyState in chat stories - Panel View now has streaming, triggers, attachments, tool calls — same features as Full AI Chat but in a 400×600 sidebar container - Replace inline empty state markup with XDSEmptyState in both ChatLayout and ChatMessageList stories * fix(ProgressBar): add minWidth so bar doesn't collapse in flex layouts Without a minWidth, the progress bar container could shrink to zero inside flex parents (e.g. the composer header slot). 48px ensures the track is always visible. * fix(ProgressBar): add neutral variant to stories * fix(Chat): remove headerRight minWidth, apply margin directly on ProgressBar * fix(ProgressBar): spread rest props + minWidth, restore direct tooltip ref in story * fix(Chat): scroll-to-bottom button offsets above composer dock XDSChatLayoutContext now provides dockHeight, which the message list uses to position the scroll-to-bottom button above the composer. No arbitrary values for consumers — the layout measures the dock and provides the offset automatically. Also: ProgressBar now spreads rest props (aria-describedby, etc). * refactor(Chat): move auto-scroll from MessageList to Layout XDSChatMessageList is now purely presentational — messages, density context, empty state, spacer, infinite scroll sentinel. No scroll behavior, no scroll button. XDSChatLayout owns all scroll concerns: - useAutoScroll for scroll-to-bottom and new message detection - ResizeObserver on the message content area (via contentRef in context) to detect height changes from new/streaming content - ScrollToBottomButton rendered above the composer dock - Scroll listener attached to the scroll container The layout context provides contentRef — the message list attaches it to its inner element so the layout can observe height changes. No effects on children, no callbacks — just measurement. useAutoScroll and ScrollToBottomButton remain exported for standalone composition without XDSChatLayout. * fix(Chat): count .xds-chat-message elements to detect new messages ResizeObserver on the content area now checks the message count against a ref. Only triggers onContentChange when messages are added — not when existing content resizes (tool call expand, drawer collapse, etc). * fix(Chat): track last message element instead of counting Replaces querySelectorAll count with a reference comparison on the last .xds-chat-message element. Faster (getElementsByClassName is a live collection, just grab the last one) and correctly ignores upward loads — prepending old messages doesn't change the last element. * fix(Chat): use mentionTokens not msg.tokens in stories, unify dock/blur position * fix(Chat): use absolute positioning for dock/blur in self-scrolling layout Sticky doesn't work when content is shorter than the container. Absolute + bottom: 0 anchors to the layout root regardless of content height. * rename XDSChatMessageTokenizedText → XDSChatTokenizedText, guard undefined children - Rename component + file + test + all story references - Re-export old name as deprecated alias for backwards compat - Guard against undefined children (fixes e.replace crash during streaming) - Fix MessageList test: scroll button now owned by Layout * chore: remove deprecated XDSChatMessageTokenizedText alias * docs(Chat): update docs to reflect auto-scroll ownership move to Layout - Remove hasAutoScroll/scrollThreshold from MessageList docs - Add hasAutoScroll/newMessagesLabel to Layout docs - Update MessageList descriptions across all doc variants - All three doc variants (main, zh, dense) now consistent * test(Chat): move scroll button test to Layout, remove negative assertion from MessageList * fix(Chat): use value not pattern in mentionTokens (matches XDSChatComposerToken) * fix(Chat): sticky dock + min-height 100% on message area Absolute positioning broke layout flow. Sticky works correctly when the message area has min-height: 100% — the dock always has content to stick against, even when messages are short. * fix(Chat): handle backspace near tokens in ComposerInput Intercept Backspace when the cursor is in the trailing NBSP after a token. Instead of letting the browser mangle the DOM (creating stray <br> or moving the cursor before the token), we remove both the NBSP and the token in one clean action. Fixes: backspace on '@sam ' producing '@sam\n' then '\n' * test(Chat): add token backspace tests for ComposerInput Tests that backspace near a token removes both the trailing NBSP and the token span in one action, and that onChange fires with empty string. * fix(Chat): single sticky container for blur layer + composer dock Blur layer and composer are now siblings inside one sticky/fixed container. Previously they were separate sticky elements that could desync. The blur layer is position: absolute within the container, the composer sits above it with position: relative. * fix(Chat): dock container isolation: isolate + zIndex: 0, fix missing styles * fix(Chat): remove dockHeight padding, center scroll-to-bottom button - Remove paddingBlockEnd: dockHeight + 24 from message area — sticky dock is in flow, no clearance needed - Replace float/translate hack with a flex wrapper that centers the button. Wrapper is sticky + height: 0 + pointer-events: none so it doesn't affect layout. * fix(Chat): add spacing-6 bottom padding to message area, scroll button clears dock * fix(Chat): remove dockHeight — not needed with sticky layout Scroll button is in flow above the dock, no offset computation needed. Removed dockHeight state, ResizeObserver, and context prop. Button uses a centered sticky wrapper with bottom: --spacing-3. * fix(Chat): scroll button inside sticky dock container Move scroll-to-bottom button into the dock container as a sibling above the composer. Container is pointer-events: none so it doesn't block clicks on content behind it. Composer and scroll button opt back in with pointer-events: auto. * fix(Chat): use state for contentEl so ResizeObserver connects on mount contentElRef was a ref — the ResizeObserver effect ran before the message list registered its element, and never re-ran. Switching to state triggers a re-render when the message list calls contentRef, which re-runs the effect and connects the observer. * refactor(Chat): callback ref for content observer instead of state Callback ref fires synchronously when the message list registers its element — no effect timing issues. The ResizeObserver connects and disconnects inside the callback, managed via observerRef. * refactor(Chat): single ResizeObserver for density + content changes One observer instance watches both the root (for density breakpoints) and the content element (for new messages). Dispatches by checking entry.target. Reduces observer count from 2 to 1. * simplify: run both density + message checks on every resize callback * simplify(Chat): observe root only — remove contentRef plumbing Root resizes when content grows. One ResizeObserver on root handles both density and new message detection. Removed contentRef from context, callback ref, and message list registration. * fix(Chat): scroll listener + initial scroll after root mounts scrollRef.current was null when the scroll listener effect first ran. Track root mount via state so the effect re-runs once the element exists. Also calls scrollToBottom(false) when the listener attaches. * fix(Chat): callback ref for scroll listener — no state needed * fix(Chat): defer initial scrollToBottom to next frame Callback ref fires during commit before layout is complete. requestAnimationFrame ensures content has rendered and scrollHeight is accurate before scrolling to bottom. * fix(Chat): separate scroll container (root) from content observer (message list) Root is the scroll container — it doesn't resize when messages grow, it scrolls. The message list inner div is what actually changes height. Two observers: - Root: density breakpoints (clientWidth) - Content: new message detection (last .xds-chat-message element) Message list registers its inner div via contentRef in context. * fix(Chat): auto-scroll during streaming without triggering new messages Two resize behaviors: - Last message changed → onContentChange (auto-scroll or 'new messages') - Same message growing (streaming) → scrollToBottomIfNearBottom (auto-scroll if near bottom, no 'new messages' flag) Added scrollToBottomIfNearBottom to useAutoScroll — scrolls only if near bottom, silently ignores if scrolled up. * refactor(Chat): scroll-lock model replaces distance-threshold auto-scroll Instead of measuring distance from bottom on every scroll event to decide if we're 'near enough', use a binary lock: - Locked (default): auto-scroll follows content, streaming stays pinned - User scrolls up: unlock — auto-scroll stops, new messages flagged - User scrolls to bottom: re-lock — auto-scroll resumes Programmatic scrolls (our scrollToBottom calls) are flagged via isProgrammaticRef so they don't affect the lock state. The flag clears on the next animation frame. scrollToBottomIfLocked replaces scrollToBottomIfNearBottom — used for streaming content growth (same message getting taller). * simplify(Chat): remove isProgrammaticRef — scroll position self-corrects scrollToBottom scrolls to bottom → scroll event fires → distance is 0 → re-locks. User scrolls up → distance > threshold → unlocks. No need to distinguish programmatic vs user scrolls. * fix(Chat): only unlock on upward wheel scroll, attach wheel/touch listeners Wheel events scrolling down at the bottom were unlocking the scroll lock momentarily — enough for a content change to miss the lock and not auto-scroll. Now only deltaY < 0 (scroll up) unlocks. Also wired up wheel + touchmove listeners on the scroll container and separated handleUserScroll (unlock) from handleScroll (re-lock). * fix(Chat): two-step unlock — wheel sets intent, scroll confirms position Wheel/touch sets userScrollingRef flag. handleScroll only unlocks if that flag is set AND the user has actually scrolled beyond scrollUpThreshold. Prevents micro-scrolls and trackpad noise from breaking the lock. Also: handleScroll no longer re-locks — only dismissNewMessages does. Auto-scroll on any height change (not just new messages). Removed bottomThreshold (unused). * fix(Chat): use scrollend + isProgrammatic flag for reliable lock scrollend fires once when scrolling settles. If isProgrammaticRef is set, it was our scroll → clear flag, stay locked. If not set, it was a user scroll → unlock immediately. No wheel/touch listeners needed. No distance threshold for unlock. Clean separation: programmatic scrolls never unlock, user scrolls always unlock. * fix(Chat): unlock on scroll (immediate), clear programmatic flag on scrollend User scroll → handleScroll → isProgrammatic is false → unlock immediately. Programmatic scroll → isProgrammatic is true → handleScroll skips unlock → scrollend clears flag. * fix(Chat): re-lock on scrollend if user scrolled back to bottom * fix(Chat): clean scroll lock logic - On scroll: if not programmatic AND past threshold → unlock - On scroll end: if at bottom → lock - Content grows + locked → scroll to bottom * fix(Chat): wheel/touch clears programmatic flag to interrupt auto-scroll If the user scrolls during a programmatic smooth scroll, the wheel/ touchstart handler clears isProgrammaticRef so the next handleScroll event can unlock normally. Prevents the auto-scroll from fighting the user back to the bottom. * debug(Chat): add console.debug to auto-scroll for investigation Logs at every decision point: scrollToBottom, unlock, scrollend, user interrupt, content grew (locked/unlocked), new msg flagged. Filter console by '[auto-scroll]' in devtools. * chore: remove debug console.debug statements from useAutoScroll --------- Co-authored-by: Navi <[email protected]>
cixzhang
added a commit
that referenced
this pull request
Jun 21, 2026
…queries (#1249) * feat(Chat): add XDSChatLayout with fixed composer dock and container query density * feat(Chat): scrollRef prop on XDSChatLayout + auto-scroll delegation XDSChatLayout now provides a scroll container context that XDSChatMessageList picks up automatically. Auto-scroll, scroll-to-bottom, and new message detection all target the correct scrollable ancestor. - Add scrollRef prop to XDSChatLayout — delegates scrolling to a parent element or document body when the layout isn't the scroll container - Add XDSChatLayoutContext — passes scroll container ref to descendants - useAutoScroll accepts optional scrollContainerRef - XDSChatMessageList reads layout context and disables its own overflow when inside a layout (scroll container is the layout root) - Update Chat.doc.mjs with scrollRef prop docs and examples * fix(Chat): sticky composer dock in panel layouts * feat(Chat): full-featured Panel View story + XDSEmptyState in chat stories - Panel View now has streaming, triggers, attachments, tool calls — same features as Full AI Chat but in a 400×600 sidebar container - Replace inline empty state markup with XDSEmptyState in both ChatLayout and ChatMessageList stories * fix(ProgressBar): add minWidth so bar doesn't collapse in flex layouts Without a minWidth, the progress bar container could shrink to zero inside flex parents (e.g. the composer header slot). 48px ensures the track is always visible. * fix(ProgressBar): add neutral variant to stories * fix(Chat): remove headerRight minWidth, apply margin directly on ProgressBar * fix(ProgressBar): spread rest props + minWidth, restore direct tooltip ref in story * fix(Chat): scroll-to-bottom button offsets above composer dock XDSChatLayoutContext now provides dockHeight, which the message list uses to position the scroll-to-bottom button above the composer. No arbitrary values for consumers — the layout measures the dock and provides the offset automatically. Also: ProgressBar now spreads rest props (aria-describedby, etc). * refactor(Chat): move auto-scroll from MessageList to Layout XDSChatMessageList is now purely presentational — messages, density context, empty state, spacer, infinite scroll sentinel. No scroll behavior, no scroll button. XDSChatLayout owns all scroll concerns: - useAutoScroll for scroll-to-bottom and new message detection - ResizeObserver on the message content area (via contentRef in context) to detect height changes from new/streaming content - ScrollToBottomButton rendered above the composer dock - Scroll listener attached to the scroll container The layout context provides contentRef — the message list attaches it to its inner element so the layout can observe height changes. No effects on children, no callbacks — just measurement. useAutoScroll and ScrollToBottomButton remain exported for standalone composition without XDSChatLayout. * fix(Chat): count .xds-chat-message elements to detect new messages ResizeObserver on the content area now checks the message count against a ref. Only triggers onContentChange when messages are added — not when existing content resizes (tool call expand, drawer collapse, etc). * fix(Chat): track last message element instead of counting Replaces querySelectorAll count with a reference comparison on the last .xds-chat-message element. Faster (getElementsByClassName is a live collection, just grab the last one) and correctly ignores upward loads — prepending old messages doesn't change the last element. * fix(Chat): use mentionTokens not msg.tokens in stories, unify dock/blur position * fix(Chat): use absolute positioning for dock/blur in self-scrolling layout Sticky doesn't work when content is shorter than the container. Absolute + bottom: 0 anchors to the layout root regardless of content height. * rename XDSChatMessageTokenizedText → XDSChatTokenizedText, guard undefined children - Rename component + file + test + all story references - Re-export old name as deprecated alias for backwards compat - Guard against undefined children (fixes e.replace crash during streaming) - Fix MessageList test: scroll button now owned by Layout * chore: remove deprecated XDSChatMessageTokenizedText alias * docs(Chat): update docs to reflect auto-scroll ownership move to Layout - Remove hasAutoScroll/scrollThreshold from MessageList docs - Add hasAutoScroll/newMessagesLabel to Layout docs - Update MessageList descriptions across all doc variants - All three doc variants (main, zh, dense) now consistent * test(Chat): move scroll button test to Layout, remove negative assertion from MessageList * fix(Chat): use value not pattern in mentionTokens (matches XDSChatComposerToken) * fix(Chat): sticky dock + min-height 100% on message area Absolute positioning broke layout flow. Sticky works correctly when the message area has min-height: 100% — the dock always has content to stick against, even when messages are short. * fix(Chat): handle backspace near tokens in ComposerInput Intercept Backspace when the cursor is in the trailing NBSP after a token. Instead of letting the browser mangle the DOM (creating stray <br> or moving the cursor before the token), we remove both the NBSP and the token in one clean action. Fixes: backspace on '@sam ' producing '@sam\n' then '\n' * test(Chat): add token backspace tests for ComposerInput Tests that backspace near a token removes both the trailing NBSP and the token span in one action, and that onChange fires with empty string. * fix(Chat): single sticky container for blur layer + composer dock Blur layer and composer are now siblings inside one sticky/fixed container. Previously they were separate sticky elements that could desync. The blur layer is position: absolute within the container, the composer sits above it with position: relative. * fix(Chat): dock container isolation: isolate + zIndex: 0, fix missing styles * fix(Chat): remove dockHeight padding, center scroll-to-bottom button - Remove paddingBlockEnd: dockHeight + 24 from message area — sticky dock is in flow, no clearance needed - Replace float/translate hack with a flex wrapper that centers the button. Wrapper is sticky + height: 0 + pointer-events: none so it doesn't affect layout. * fix(Chat): add spacing-6 bottom padding to message area, scroll button clears dock * fix(Chat): remove dockHeight — not needed with sticky layout Scroll button is in flow above the dock, no offset computation needed. Removed dockHeight state, ResizeObserver, and context prop. Button uses a centered sticky wrapper with bottom: --spacing-3. * fix(Chat): scroll button inside sticky dock container Move scroll-to-bottom button into the dock container as a sibling above the composer. Container is pointer-events: none so it doesn't block clicks on content behind it. Composer and scroll button opt back in with pointer-events: auto. * fix(Chat): use state for contentEl so ResizeObserver connects on mount contentElRef was a ref — the ResizeObserver effect ran before the message list registered its element, and never re-ran. Switching to state triggers a re-render when the message list calls contentRef, which re-runs the effect and connects the observer. * refactor(Chat): callback ref for content observer instead of state Callback ref fires synchronously when the message list registers its element — no effect timing issues. The ResizeObserver connects and disconnects inside the callback, managed via observerRef. * refactor(Chat): single ResizeObserver for density + content changes One observer instance watches both the root (for density breakpoints) and the content element (for new messages). Dispatches by checking entry.target. Reduces observer count from 2 to 1. * simplify: run both density + message checks on every resize callback * simplify(Chat): observe root only — remove contentRef plumbing Root resizes when content grows. One ResizeObserver on root handles both density and new message detection. Removed contentRef from context, callback ref, and message list registration. * fix(Chat): scroll listener + initial scroll after root mounts scrollRef.current was null when the scroll listener effect first ran. Track root mount via state so the effect re-runs once the element exists. Also calls scrollToBottom(false) when the listener attaches. * fix(Chat): callback ref for scroll listener — no state needed * fix(Chat): defer initial scrollToBottom to next frame Callback ref fires during commit before layout is complete. requestAnimationFrame ensures content has rendered and scrollHeight is accurate before scrolling to bottom. * fix(Chat): separate scroll container (root) from content observer (message list) Root is the scroll container — it doesn't resize when messages grow, it scrolls. The message list inner div is what actually changes height. Two observers: - Root: density breakpoints (clientWidth) - Content: new message detection (last .xds-chat-message element) Message list registers its inner div via contentRef in context. * fix(Chat): auto-scroll during streaming without triggering new messages Two resize behaviors: - Last message changed → onContentChange (auto-scroll or 'new messages') - Same message growing (streaming) → scrollToBottomIfNearBottom (auto-scroll if near bottom, no 'new messages' flag) Added scrollToBottomIfNearBottom to useAutoScroll — scrolls only if near bottom, silently ignores if scrolled up. * refactor(Chat): scroll-lock model replaces distance-threshold auto-scroll Instead of measuring distance from bottom on every scroll event to decide if we're 'near enough', use a binary lock: - Locked (default): auto-scroll follows content, streaming stays pinned - User scrolls up: unlock — auto-scroll stops, new messages flagged - User scrolls to bottom: re-lock — auto-scroll resumes Programmatic scrolls (our scrollToBottom calls) are flagged via isProgrammaticRef so they don't affect the lock state. The flag clears on the next animation frame. scrollToBottomIfLocked replaces scrollToBottomIfNearBottom — used for streaming content growth (same message getting taller). * simplify(Chat): remove isProgrammaticRef — scroll position self-corrects scrollToBottom scrolls to bottom → scroll event fires → distance is 0 → re-locks. User scrolls up → distance > threshold → unlocks. No need to distinguish programmatic vs user scrolls. * fix(Chat): only unlock on upward wheel scroll, attach wheel/touch listeners Wheel events scrolling down at the bottom were unlocking the scroll lock momentarily — enough for a content change to miss the lock and not auto-scroll. Now only deltaY < 0 (scroll up) unlocks. Also wired up wheel + touchmove listeners on the scroll container and separated handleUserScroll (unlock) from handleScroll (re-lock). * fix(Chat): two-step unlock — wheel sets intent, scroll confirms position Wheel/touch sets userScrollingRef flag. handleScroll only unlocks if that flag is set AND the user has actually scrolled beyond scrollUpThreshold. Prevents micro-scrolls and trackpad noise from breaking the lock. Also: handleScroll no longer re-locks — only dismissNewMessages does. Auto-scroll on any height change (not just new messages). Removed bottomThreshold (unused). * fix(Chat): use scrollend + isProgrammatic flag for reliable lock scrollend fires once when scrolling settles. If isProgrammaticRef is set, it was our scroll → clear flag, stay locked. If not set, it was a user scroll → unlock immediately. No wheel/touch listeners needed. No distance threshold for unlock. Clean separation: programmatic scrolls never unlock, user scrolls always unlock. * fix(Chat): unlock on scroll (immediate), clear programmatic flag on scrollend User scroll → handleScroll → isProgrammatic is false → unlock immediately. Programmatic scroll → isProgrammatic is true → handleScroll skips unlock → scrollend clears flag. * fix(Chat): re-lock on scrollend if user scrolled back to bottom * fix(Chat): clean scroll lock logic - On scroll: if not programmatic AND past threshold → unlock - On scroll end: if at bottom → lock - Content grows + locked → scroll to bottom * fix(Chat): wheel/touch clears programmatic flag to interrupt auto-scroll If the user scrolls during a programmatic smooth scroll, the wheel/ touchstart handler clears isProgrammaticRef so the next handleScroll event can unlock normally. Prevents the auto-scroll from fighting the user back to the bottom. * debug(Chat): add console.debug to auto-scroll for investigation Logs at every decision point: scrollToBottom, unlock, scrollend, user interrupt, content grew (locked/unlocked), new msg flagged. Filter console by '[auto-scroll]' in devtools. * chore: remove debug console.debug statements from useAutoScroll --------- Co-authored-by: Navi <[email protected]>
cixzhang
added a commit
that referenced
this pull request
Jun 21, 2026
…queries (#1249) * feat(Chat): add XDSChatLayout with fixed composer dock and container query density * feat(Chat): scrollRef prop on XDSChatLayout + auto-scroll delegation XDSChatLayout now provides a scroll container context that XDSChatMessageList picks up automatically. Auto-scroll, scroll-to-bottom, and new message detection all target the correct scrollable ancestor. - Add scrollRef prop to XDSChatLayout — delegates scrolling to a parent element or document body when the layout isn't the scroll container - Add XDSChatLayoutContext — passes scroll container ref to descendants - useAutoScroll accepts optional scrollContainerRef - XDSChatMessageList reads layout context and disables its own overflow when inside a layout (scroll container is the layout root) - Update Chat.doc.mjs with scrollRef prop docs and examples * fix(Chat): sticky composer dock in panel layouts * feat(Chat): full-featured Panel View story + XDSEmptyState in chat stories - Panel View now has streaming, triggers, attachments, tool calls — same features as Full AI Chat but in a 400×600 sidebar container - Replace inline empty state markup with XDSEmptyState in both ChatLayout and ChatMessageList stories * fix(ProgressBar): add minWidth so bar doesn't collapse in flex layouts Without a minWidth, the progress bar container could shrink to zero inside flex parents (e.g. the composer header slot). 48px ensures the track is always visible. * fix(ProgressBar): add neutral variant to stories * fix(Chat): remove headerRight minWidth, apply margin directly on ProgressBar * fix(ProgressBar): spread rest props + minWidth, restore direct tooltip ref in story * fix(Chat): scroll-to-bottom button offsets above composer dock XDSChatLayoutContext now provides dockHeight, which the message list uses to position the scroll-to-bottom button above the composer. No arbitrary values for consumers — the layout measures the dock and provides the offset automatically. Also: ProgressBar now spreads rest props (aria-describedby, etc). * refactor(Chat): move auto-scroll from MessageList to Layout XDSChatMessageList is now purely presentational — messages, density context, empty state, spacer, infinite scroll sentinel. No scroll behavior, no scroll button. XDSChatLayout owns all scroll concerns: - useAutoScroll for scroll-to-bottom and new message detection - ResizeObserver on the message content area (via contentRef in context) to detect height changes from new/streaming content - ScrollToBottomButton rendered above the composer dock - Scroll listener attached to the scroll container The layout context provides contentRef — the message list attaches it to its inner element so the layout can observe height changes. No effects on children, no callbacks — just measurement. useAutoScroll and ScrollToBottomButton remain exported for standalone composition without XDSChatLayout. * fix(Chat): count .xds-chat-message elements to detect new messages ResizeObserver on the content area now checks the message count against a ref. Only triggers onContentChange when messages are added — not when existing content resizes (tool call expand, drawer collapse, etc). * fix(Chat): track last message element instead of counting Replaces querySelectorAll count with a reference comparison on the last .xds-chat-message element. Faster (getElementsByClassName is a live collection, just grab the last one) and correctly ignores upward loads — prepending old messages doesn't change the last element. * fix(Chat): use mentionTokens not msg.tokens in stories, unify dock/blur position * fix(Chat): use absolute positioning for dock/blur in self-scrolling layout Sticky doesn't work when content is shorter than the container. Absolute + bottom: 0 anchors to the layout root regardless of content height. * rename XDSChatMessageTokenizedText → XDSChatTokenizedText, guard undefined children - Rename component + file + test + all story references - Re-export old name as deprecated alias for backwards compat - Guard against undefined children (fixes e.replace crash during streaming) - Fix MessageList test: scroll button now owned by Layout * chore: remove deprecated XDSChatMessageTokenizedText alias * docs(Chat): update docs to reflect auto-scroll ownership move to Layout - Remove hasAutoScroll/scrollThreshold from MessageList docs - Add hasAutoScroll/newMessagesLabel to Layout docs - Update MessageList descriptions across all doc variants - All three doc variants (main, zh, dense) now consistent * test(Chat): move scroll button test to Layout, remove negative assertion from MessageList * fix(Chat): use value not pattern in mentionTokens (matches XDSChatComposerToken) * fix(Chat): sticky dock + min-height 100% on message area Absolute positioning broke layout flow. Sticky works correctly when the message area has min-height: 100% — the dock always has content to stick against, even when messages are short. * fix(Chat): handle backspace near tokens in ComposerInput Intercept Backspace when the cursor is in the trailing NBSP after a token. Instead of letting the browser mangle the DOM (creating stray <br> or moving the cursor before the token), we remove both the NBSP and the token in one clean action. Fixes: backspace on '@sam ' producing '@sam\n' then '\n' * test(Chat): add token backspace tests for ComposerInput Tests that backspace near a token removes both the trailing NBSP and the token span in one action, and that onChange fires with empty string. * fix(Chat): single sticky container for blur layer + composer dock Blur layer and composer are now siblings inside one sticky/fixed container. Previously they were separate sticky elements that could desync. The blur layer is position: absolute within the container, the composer sits above it with position: relative. * fix(Chat): dock container isolation: isolate + zIndex: 0, fix missing styles * fix(Chat): remove dockHeight padding, center scroll-to-bottom button - Remove paddingBlockEnd: dockHeight + 24 from message area — sticky dock is in flow, no clearance needed - Replace float/translate hack with a flex wrapper that centers the button. Wrapper is sticky + height: 0 + pointer-events: none so it doesn't affect layout. * fix(Chat): add spacing-6 bottom padding to message area, scroll button clears dock * fix(Chat): remove dockHeight — not needed with sticky layout Scroll button is in flow above the dock, no offset computation needed. Removed dockHeight state, ResizeObserver, and context prop. Button uses a centered sticky wrapper with bottom: --spacing-3. * fix(Chat): scroll button inside sticky dock container Move scroll-to-bottom button into the dock container as a sibling above the composer. Container is pointer-events: none so it doesn't block clicks on content behind it. Composer and scroll button opt back in with pointer-events: auto. * fix(Chat): use state for contentEl so ResizeObserver connects on mount contentElRef was a ref — the ResizeObserver effect ran before the message list registered its element, and never re-ran. Switching to state triggers a re-render when the message list calls contentRef, which re-runs the effect and connects the observer. * refactor(Chat): callback ref for content observer instead of state Callback ref fires synchronously when the message list registers its element — no effect timing issues. The ResizeObserver connects and disconnects inside the callback, managed via observerRef. * refactor(Chat): single ResizeObserver for density + content changes One observer instance watches both the root (for density breakpoints) and the content element (for new messages). Dispatches by checking entry.target. Reduces observer count from 2 to 1. * simplify: run both density + message checks on every resize callback * simplify(Chat): observe root only — remove contentRef plumbing Root resizes when content grows. One ResizeObserver on root handles both density and new message detection. Removed contentRef from context, callback ref, and message list registration. * fix(Chat): scroll listener + initial scroll after root mounts scrollRef.current was null when the scroll listener effect first ran. Track root mount via state so the effect re-runs once the element exists. Also calls scrollToBottom(false) when the listener attaches. * fix(Chat): callback ref for scroll listener — no state needed * fix(Chat): defer initial scrollToBottom to next frame Callback ref fires during commit before layout is complete. requestAnimationFrame ensures content has rendered and scrollHeight is accurate before scrolling to bottom. * fix(Chat): separate scroll container (root) from content observer (message list) Root is the scroll container — it doesn't resize when messages grow, it scrolls. The message list inner div is what actually changes height. Two observers: - Root: density breakpoints (clientWidth) - Content: new message detection (last .xds-chat-message element) Message list registers its inner div via contentRef in context. * fix(Chat): auto-scroll during streaming without triggering new messages Two resize behaviors: - Last message changed → onContentChange (auto-scroll or 'new messages') - Same message growing (streaming) → scrollToBottomIfNearBottom (auto-scroll if near bottom, no 'new messages' flag) Added scrollToBottomIfNearBottom to useAutoScroll — scrolls only if near bottom, silently ignores if scrolled up. * refactor(Chat): scroll-lock model replaces distance-threshold auto-scroll Instead of measuring distance from bottom on every scroll event to decide if we're 'near enough', use a binary lock: - Locked (default): auto-scroll follows content, streaming stays pinned - User scrolls up: unlock — auto-scroll stops, new messages flagged - User scrolls to bottom: re-lock — auto-scroll resumes Programmatic scrolls (our scrollToBottom calls) are flagged via isProgrammaticRef so they don't affect the lock state. The flag clears on the next animation frame. scrollToBottomIfLocked replaces scrollToBottomIfNearBottom — used for streaming content growth (same message getting taller). * simplify(Chat): remove isProgrammaticRef — scroll position self-corrects scrollToBottom scrolls to bottom → scroll event fires → distance is 0 → re-locks. User scrolls up → distance > threshold → unlocks. No need to distinguish programmatic vs user scrolls. * fix(Chat): only unlock on upward wheel scroll, attach wheel/touch listeners Wheel events scrolling down at the bottom were unlocking the scroll lock momentarily — enough for a content change to miss the lock and not auto-scroll. Now only deltaY < 0 (scroll up) unlocks. Also wired up wheel + touchmove listeners on the scroll container and separated handleUserScroll (unlock) from handleScroll (re-lock). * fix(Chat): two-step unlock — wheel sets intent, scroll confirms position Wheel/touch sets userScrollingRef flag. handleScroll only unlocks if that flag is set AND the user has actually scrolled beyond scrollUpThreshold. Prevents micro-scrolls and trackpad noise from breaking the lock. Also: handleScroll no longer re-locks — only dismissNewMessages does. Auto-scroll on any height change (not just new messages). Removed bottomThreshold (unused). * fix(Chat): use scrollend + isProgrammatic flag for reliable lock scrollend fires once when scrolling settles. If isProgrammaticRef is set, it was our scroll → clear flag, stay locked. If not set, it was a user scroll → unlock immediately. No wheel/touch listeners needed. No distance threshold for unlock. Clean separation: programmatic scrolls never unlock, user scrolls always unlock. * fix(Chat): unlock on scroll (immediate), clear programmatic flag on scrollend User scroll → handleScroll → isProgrammatic is false → unlock immediately. Programmatic scroll → isProgrammatic is true → handleScroll skips unlock → scrollend clears flag. * fix(Chat): re-lock on scrollend if user scrolled back to bottom * fix(Chat): clean scroll lock logic - On scroll: if not programmatic AND past threshold → unlock - On scroll end: if at bottom → lock - Content grows + locked → scroll to bottom * fix(Chat): wheel/touch clears programmatic flag to interrupt auto-scroll If the user scrolls during a programmatic smooth scroll, the wheel/ touchstart handler clears isProgrammaticRef so the next handleScroll event can unlock normally. Prevents the auto-scroll from fighting the user back to the bottom. * debug(Chat): add console.debug to auto-scroll for investigation Logs at every decision point: scrollToBottom, unlock, scrollend, user interrupt, content grew (locked/unlocked), new msg flagged. Filter console by '[auto-scroll]' in devtools. * chore: remove debug console.debug statements from useAutoScroll ---------
This was referenced Aug 29, 2026
cixzhang
pushed a commit
that referenced
this pull request
Sep 4, 2026
) * fix(chat): gestures vouch for their scroll instead of unlocking (#5662) `onWheel` and `onTouchMove` gated on `animatingRef`, which has meant "we are following" only by coincidence. #4104 added a reduced-motion path that follows without ever starting a spring, so both handlers became permanent no-ops for readers with reduced motion, and the remaining release path — `onScroll`'s direction check — is blind exactly when it matters, since arriving content changes the geometry on nearly every event. Restores the arbitration this hook was extracted from (#1249): the gesture does not unlock, it clears the suppression so the scroll it produces is read as intent. Here that means waiving the synthetic-resize guard for the frames the gesture covers and letting the direction check decide. A gesture this scroller never consumed — a wheel over a nested scrollable child, an overscroll at the bottom — produces no scroll event and now leaves following alone, where before it released the tail whenever the spring was live. `touchstart` replaces `touchmove` for the reason it was the original listener: it fires once, before any movement, and needs no per-drag bookkeeping. `jumpToBottom` (#3800) also cleared `animatingRef` while `lockedRef` stayed true, which no other caller did, so a running loop survived its own cancellation and the next `startAnimation` stacked a second one on top (#5663). A generation token makes the documented cancel real; with the gesture handlers off `animatingRef`, it is loop bookkeeping again. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(chat): a resize clamp landing on the bottom is never a release A finger resting on a nested scrollable child bubbles `touchstart` to the chat scroller, so the gesture waiver was live for a drag this scroller never consumed. If an earlier block collapsed while the finger was down, the browser clamped `scrollTop` up to the new bottom and the waived guard read that clamp as the reader scrolling: following released, and the lines streamed next stayed below the fold. The wheel waiver had the same hole, two frames wide. A clamp can only ever land on the new maximum, and a reader scrolling up never lands there. So a scroll that arrives with changed geometry and ends at the bottom is the clamp regardless of any gesture, and the guard now keeps it synthetic. The waiver still lets a real scroll-up through while content is arriving, which is what it was for. Co-Authored-By: Claude Fable 5.1 <[email protected]> * refactor(chat): cancel the spring's frame instead of tagging generations The loop's continuation is always one pending rAF handle, and `jumpToBottom` only ever runs from an event or another frame callback, so `cancelAnimationFrame` on that handle is an exact cancel — the same `rafRef` shape `useChatDictation` and `useSpeechRecognition` use. `animate` goes back to taking no argument, and the generation counter, its per-frame closure, and the check at the top of the tick are gone. The test double now hands out real ids and honours cancellation, so the stacked-loop test keeps proving the same thing. Comments around the synthetic-resize guard and the wheel waiver are folded down to what the code no longer says on its own. Co-Authored-By: Claude Fable 5.1 <[email protected]> * fix(chat): only a gesture this scroller consumes waives the guard A bubbled gesture was treated as ownership of every scroll that followed. With the spring trailing a fast stream, a finger resting on a nested scroller plus a collapse above the viewport moved scrollTop up by scroll anchoring — not a clamp, so it did not land on the bottom — and the waived guard read the shift as the reader. Following released. Ownership now comes from the gesture itself. A wheel up vouches only when no vertically scrollable element between its target and this scroller still has room above; scroll chaining hands a gesture outward only from a scroller at its edge. A drag records its target and finger position on touchstart and vouches from the first touchmove that pushes this scroller up, under the same nested check, until the finger lifts. A resting finger is not a gesture. The bottom-landing rule stays for the one clamp a consumed gesture can still coincide with: an overscroll at the bottom while a block above collapses. Co-Authored-By: Claude Fable 5.1 <[email protected]> * fix(chat): own the position while following instead of judging gestures Every revision so far inferred whether a scroll was the reader's from the gesture that preceded it, and every inference has a counterexample: a bubbled touchstart, a nested scroller at its edge, then one with `overscroll-behavior: contain`. The question was never who owns the gesture. It is what can move a following container up other than the reader, and there are two answers: the resize clamp onto the bottom, and CSS scroll anchoring. The clamp lands exactly on the bottom, which the guard already checks. Anchoring is switched off on the scroll element while following and restored when not — the hook is the only writer of the position while locked, so anchoring has nothing to do there, and a reader up in the history keeps it. With that, any upward scroll that does not land on the bottom is the reader, and the wheel and touch listeners, the gesture waiver, the two-frame expiry, and the synthetic-resize tracking all go. Same shape as ListInput (#4740) and LegendList's maintainVisibleContentPosition, for the same reason. Co-Authored-By: Claude Fable 5.1 <[email protected]> * fix(chat): hand back the scroll element's own overflow-anchor Unlocking wrote '' over whatever inline overflow-anchor the consumer had set, so a scroller that had disabled anchoring itself got it back once the reader scrolled up. Capture the element's inline value when the hook takes it over and restore that value on unlock and on cleanup. Co-Authored-By: Claude Fable 5.1 <[email protected]> * fix(chat): judge a scroll against the hook's own last write Two ownership gaps from review. A reader's wheel that lands between two spring frames was compared against the last observed position, and the next frame's write outran it — net position still advanced, so the reader stayed pinned. The spring now records the position it wrote, so the coalesced scroll event that follows reads below it and releases; the same comparison use-stick-to-bottom makes against the position it set (`ignoreScrollToTop`). And the anchoring switch no longer goes through the element's inline style at all. It is an attribute, `data-astryx-chat-following`, and one injected rule with `!important`, the pattern `highlightRanges` uses for its dynamic stylesheet. A consumer's own `overflow-anchor` is never read, written or restored — whatever they set, before or during a lock, is what applies once the attribute is gone. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
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.
What
New
XDSChatLayoutcomponent — layout shell for full chat interfaces.Architecture
position: fixedat viewport bottom with frosted glass (backdrop-filter: blur(12px)) and CSS mask gradient fade at topBreakpoints
API
Files
XDSChatLayout.tsx— component with ResizeObserver densityXDSChatLayout.test.tsx— 6 testsChatLayout.stories.tsx— Default, PanelView (400px), WithEmptyStateVerification