Repository navigation
Description
Problem
XDSChatMessageList always bottom-anchors its content. It renders an aria-hidden spacer <div> with flex: 1 as the first inner child, which pushes messages to the bottom of the container:
https://github.com/facebookexperimental/xds/blob/main/packages/core/src/Chat/XDSChatMessageList.tsx — see styles.spacer = { flex: 1, minHeight: 0 } and the spacer <div> rendered before children.
This is the right default for live chat (newest message visible). But some surfaces — e.g. a static/seeded conversation that fits within the viewport, or an artifact/document side-panel chat — read better top-anchored, with messages starting at the top of the panel.
Why it can't be solved at the call site today
There is no prop (align, anchor, justify, scrollAnchor, etc.) on XDSChatMessageList or XDSChatLayout to control this. xstyle is applied to the list's root, not the inner flex container or the spacer, so the spacer's flex: 1 can't be overridden from outside. StyleX has no descendant/child combinators, so a consumer cannot target the spacer via xstyle either.
The only current workarounds all reach into the component's internal DOM:
- A raw
<style>tag with a global selector like.xds-chat-message-list > div > [aria-hidden] { flex: 0 0 0 }(anti-pattern — pierces internals, leaks globally). - A
ref+useEffectsetting the spacer's inline style (still pierces internals).
Both are exactly the kind of escape hatch the design system discourages.
Proposed solution
Add an alignment prop to XDSChatMessageList, e.g.:
/**
* Vertical alignment of messages within the list when content
* doesn't fill the container.
* - 'bottom' (default): messages anchor to the bottom (live-chat behavior).
* - 'top': messages anchor to the top (static/seeded conversations,
* document/artifact side panels).
* @default 'bottom'
*/
align?: 'top' | 'bottom';Implementation: render (or collapse) the flex: 1 spacer based on align. When align === 'top', omit the spacer (or set it to flex: 0). Auto-scroll behavior owned by XDSChatLayout should still work for the bottom case.
Remember the SYNC: block at the top of XDSChatMessageList.tsx (update index exports, Storybook stories, and the ChatMessageList block examples).
Context
Surfaced while building the ai-chat-artifact page template (packages/cli/templates/pages/ai-chat-artifact/page.tsx). The template wanted top-anchored chat; we removed the <style> workaround and reverted to the default bottom-anchor rather than ship the anti-pattern, pending this prop.
Activity
fix(chat): scope to the behavior fix; scrollToBottom({behavior})
feat(chat): useChatStreamScroll initial option + scrollToBottom({inst…
fix(chat): scope to the behavior fix; scrollToBottom({behavior})
fix(chat): position the first fill instantly + scrollToBottom({behavi…
feat(chat): add ChatMessageList align prop for top-aligned lists (#2572…