Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(chat): flex-column ChatLayout root so the sticky dock doesn't add phantom scroll height (#2573) (#4202)

Jiun Shinb7bb82941d5f
diff --git a/.changeset/chatlayout-phantom-scrollbar.md b/.changeset/chatlayout-phantom-scrollbar.md
new file mode 100644
index 0000000000..85ae5add2a
--- /dev/null
+++ b/.changeset/chatlayout-phantom-scrollbar.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] ChatLayout no longer shows a phantom scrollbar in self-scroll mode when messages don't fill the viewport. The root is now a flex column: the message area flexes to fill the space the composer dock doesn't need, so the sticky dock's natural height is part of the 100% instead of overflowing past it by exactly the dock height. Long conversations still scroll and the dock still sticks; external-scrollRef mode (fixed dock) is unchanged.
+
+@jiunshinn
diff --git a/packages/core/src/Chat/ChatLayout.test.tsx b/packages/core/src/Chat/ChatLayout.test.tsx
index ce0de2fd2c..abd5a75a85 100644
--- a/packages/core/src/Chat/ChatLayout.test.tsx
+++ b/packages/core/src/Chat/ChatLayout.test.tsx
@@ -103,6 +103,63 @@ describe('ChatLayout', () => {
});
});
+// ---------------------------------------------------------------------------
+// Self-scroll layout contract (#2573)
+//
+// jsdom has no layout, so these assert the class-level CSS intent: the root
+// must be a flex column whose message area flexes (grow, no shrink) instead
+// of forcing minHeight: 100%. With minHeight: 100% the in-flow sticky dock
+// added its full height on top of the message area, so the root always
+// overflowed by exactly the dock height (phantom scrollbar). Real-layout
+// geometry was verified in a browser; see the PR for measurements.
+// ---------------------------------------------------------------------------
+
+describe('ChatLayout — self-scroll layout contract (#2573)', () => {
+ it('root is a flex column so the dock height is part of the 100%', () => {
+ render(
+ <ChatLayout composer={<div>composer</div>} data-testid="layout">
+ <div>msg</div>
+ </ChatLayout>,
+ );
+ const root = screen.getByTestId('layout');
+ expect(root).toHaveStyle({display: 'flex', flexDirection: 'column'});
+ });
+
+ it('message area flexes to fill leftover space instead of minHeight: 100%', () => {
+ render(
+ <ChatLayout composer={<div>composer</div>} data-testid="layout">
+ <div>msg</div>
+ </ChatLayout>,
+ );
+ const messageArea = screen.getByTestId('layout')
+ .firstElementChild as HTMLElement;
+ expect(messageArea).toHaveStyle({flexGrow: '1', flexShrink: '0'});
+ // minHeight: 100% is the phantom-scrollbar bug — it must not come back.
+ expect(getComputedStyle(messageArea).minHeight).not.toBe('100%');
+ });
+
+ it('dock is sticky in self-scroll mode and fixed with an external scrollRef', () => {
+ const {rerender} = render(
+ <ChatLayout composer={<div>composer</div>} data-testid="layout">
+ <div>msg</div>
+ </ChatLayout>,
+ );
+ const dock = screen.getByTestId('layout').lastElementChild as HTMLElement;
+ expect(dock).toHaveStyle({position: 'sticky'});
+
+ const scrollRef = {current: document.documentElement};
+ rerender(
+ <ChatLayout
+ composer={<div>composer</div>}
+ data-testid="layout"
+ scrollRef={scrollRef}>
+ <div>msg</div>
+ </ChatLayout>,
+ );
+ expect(dock).toHaveStyle({position: 'fixed'});
+ });
+});
+
// ---------------------------------------------------------------------------
// First-fill scroll positioning
//
diff --git a/packages/core/src/Chat/ChatLayout.tsx b/packages/core/src/Chat/ChatLayout.tsx
index 50e2e844b1..fdc9d14cd7 100644
--- a/packages/core/src/Chat/ChatLayout.tsx
+++ b/packages/core/src/Chat/ChatLayout.tsx
@@ -12,6 +12,13 @@
* Provides the scroll container ref and content ref, renders the
* scroll-to-bottom button, frosted glass dock, and message area.
*
+ * Layout contract: the root is a flex column. The message area flexes
+ * (grow 1, shrink 0) to fill the space the dock doesn't need; the sticky
+ * dock keeps its natural height in flow. Short content therefore fills
+ * exactly 100% with no overflow, and long content grows past the root so
+ * self-scroll mode scrolls (#2573). In external-scrollRef mode the dock
+ * is position: fixed (out of flow) and the message area fills the root.
+ *
* Density (compact/balanced/spacious) is controlled via a prop with
* 'balanced' as the default. No JS measurement or ResizeObserver needed.
* The container-type on root enables container queries in child components.
@@ -100,6 +107,13 @@ const styles = stylex.create({
containerType: 'inline-size',
minHeight: 0,
flex: 1,
+ // Flex column so the sticky dock's natural height is part of the 100%:
+ // messageArea flexes to fill the leftover space instead of forcing
+ // minHeight: 100% on its own. Without this, the in-flow sticky dock
+ // adds its full height on top of the 100% message area and the root
+ // always overflows by exactly the dock height (#2573).
+ display: 'flex',
+ flexDirection: 'column',
},
rootScrollable: {
overflowY: 'auto',
@@ -116,7 +130,11 @@ const styles = stylex.create({
display: 'flex',
flexDirection: 'column',
marginInline: 'auto',
- minHeight: '100%',
+ // Fill the space the dock doesn't need (grow), but never shrink below
+ // content height — long content must overflow the root so it scrolls.
+ flexGrow: 1,
+ flexShrink: 0,
+ flexBasis: 'auto',
paddingBlockEnd: spacingVars['--spacing-6'],
width: '100%',
maxWidth: '100%',
@@ -139,6 +157,9 @@ const styles = stylex.create({
zIndex: 0,
isolation: 'isolate',
pointerEvents: 'none',
+ // Keep the sticky dock at its natural height as a flex item.
+ // (Inert in fixed mode — position: fixed takes it out of flex layout.)
+ flexShrink: 0,
},
dockContainerFixed: {
position: 'fixed',