Skip to content

The agent that grows with you

fix(desktop): retire card-stack height without a completion snap

brooklyn!4bcde77e5371
diff --git a/apps/desktop/src/components/ui/card-stack.test.tsx b/apps/desktop/src/components/ui/card-stack.test.tsx
new file mode 100644
index 00000000000..b5e975eb70b
--- /dev/null
+++ b/apps/desktop/src/components/ui/card-stack.test.tsx
@@ -0,0 +1,57 @@
+import { cleanup, render, waitFor } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { stubResizeObserver } from '@/test/jsdom'
+
+import { CardStack } from './card-stack'
+
+function Stack({ items }: { items: string[] }) {
+ return (
+ <CardStack getKey={item => item} items={items} surfaceClassName="border">
+ {(item, action) => <button disabled={!action.active || action.busy}>{item}</button>}
+ </CardStack>
+ )
+}
+
+beforeEach(() => {
+ stubResizeObserver()
+ vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(96)
+})
+
+afterEach(() => {
+ cleanup()
+ vi.restoreAllMocks()
+ vi.unstubAllGlobals()
+})
+
+describe('CardStack completion footprint', () => {
+ it('retires the footprint while the final card departs, not after it disappears', () => {
+ const { container, rerender } = render(<Stack items={['first']} />)
+ const host = container.querySelector<HTMLElement>('[data-slot="card-stack"]')!
+ expect(parseFloat(host.style.minHeight)).toBeGreaterThan(0)
+
+ rerender(<Stack items={[]} />)
+
+ // The painted exit can continue, but it cannot leave its full layout
+ // height behind until the last frame and make a bottom-locked chat snap.
+ expect(host.querySelector('[data-stack-key]')).not.toBeNull()
+ expect(host.querySelector('[data-stack-key]')?.hasAttribute('inert')).toBe(true)
+ expect(host.style.minHeight).toBe('0px')
+ expect(host.style.transition).toContain('min-height')
+ })
+
+ it('keeps the next live card measured when a previous departure finishes', async () => {
+ const { container, rerender, getByRole } = render(<Stack items={['first']} />)
+ const host = container.querySelector<HTMLElement>('[data-slot="card-stack"]')!
+ const occupiedHeight = host.style.minHeight
+ rerender(<Stack items={[]} />)
+ rerender(<Stack items={['next']} />)
+
+ await waitFor(() => expect(container.querySelector('[data-stack-key="first"]')).toBeNull())
+
+ expect(container.querySelector('[data-slot="card-stack"]')).toBe(host)
+ expect((getByRole('button', { name: 'next' }) as HTMLButtonElement).disabled).toBe(false)
+ expect(host.style.minHeight).toBe(occupiedHeight)
+ expect(host.style.transition).toBe('')
+ })
+})
diff --git a/apps/desktop/src/components/ui/card-stack.tsx b/apps/desktop/src/components/ui/card-stack.tsx
index 7c7e9e87983..db968aee976 100644
--- a/apps/desktop/src/components/ui/card-stack.tsx
+++ b/apps/desktop/src/components/ui/card-stack.tsx
@@ -63,7 +63,10 @@ export function CardStack<T>({
data-stack-count={items.length}
style={{
paddingTop: !expanded && items.length ? 8 : 0,
- minHeight: items.length || height ? height + (expanded ? 0 : 8) : undefined
+ // An exiting card stays painted by AnimatePresence, but its footprint
+ // must retire continuously too or the scroller clamps by a full card.
+ minHeight: items.length ? height + (expanded ? 0 : 8) : 0,
+ transition: !items.length && !reduced ? 'min-height 220ms ease-in-out' : undefined
}}
>
{!expanded && items.length > 1 && (
@@ -84,14 +87,7 @@ export function CardStack<T>({
transition={reduced ? { duration: 0 } : PROMOTION}
/>
)}
- <AnimatePresence
- initial={false}
- onExitComplete={() => {
- if (!items.length) {
- setHeight(0)
- }
- }}
- >
+ <AnimatePresence initial={false}>
{shown.map((item, index) => (
<StackCard
expanded={expanded}