fix(desktop): match HUD transcript rows with aui_message-group slot
TurnRow roots now carry data-slot="aui_message-group", so the band's *:not([data-slot]) selector measured an empty short session as 0px. Include message-group rows while keeping the slot-less "show earlier" path. Fixes #107050 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
import { act, render } from '@testing-library/react'
|
||||
import { useRef } from 'react'
|
||||
import { type ReactNode, useRef } from 'react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { stubResizeObserver } from '@/test/jsdom'
|
||||
|
||||
import { useHudTranscriptBand } from './transcript-band'
|
||||
|
||||
function Harness({ withViewport }: { withViewport: boolean }) {
|
||||
function Harness({
|
||||
children,
|
||||
withThreadContent = true,
|
||||
withViewport
|
||||
}: {
|
||||
children?: ReactNode
|
||||
withThreadContent?: boolean
|
||||
withViewport: boolean
|
||||
}) {
|
||||
const ref = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
useHudTranscriptBand(ref)
|
||||
@@ -16,15 +24,29 @@ function Harness({ withViewport }: { withViewport: boolean }) {
|
||||
<div data-slot="composer-dock" />
|
||||
{withViewport && (
|
||||
<div data-slot="aui_thread-viewport">
|
||||
<div data-slot="aui_thread-content">
|
||||
<div>row</div>
|
||||
</div>
|
||||
{withThreadContent && <div data-slot="aui_thread-content">{children ?? <div>row</div>}</div>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function bandHeight(container: HTMLElement): number {
|
||||
const root = container.firstElementChild as HTMLElement
|
||||
|
||||
return Number.parseFloat(root.style.getPropertyValue('--hud-band-height') || '0')
|
||||
}
|
||||
|
||||
function stubMeasuredRects() {
|
||||
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
|
||||
if (this.dataset.slot === 'composer-dock') {
|
||||
return { bottom: 768, height: 58, top: 710 } as DOMRect
|
||||
}
|
||||
|
||||
return { bottom: 172, height: 72, top: 100 } as DOMRect
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
stubResizeObserver()
|
||||
vi.useFakeTimers()
|
||||
@@ -32,6 +54,7 @@ beforeEach(() => {
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('useHudTranscriptBand', () => {
|
||||
@@ -61,4 +84,48 @@ describe('useHudTranscriptBand', () => {
|
||||
|
||||
expect(muchLater).toBe(justAfterFound)
|
||||
})
|
||||
|
||||
// TurnRow roots now carry data-slot="aui_message-group". The band must still
|
||||
// treat them as transcript rows; matching only *:not([data-slot]) leaves a
|
||||
// short session at --hud-band-height: 0px and clips the transcript.
|
||||
it('measures a TurnRow with data-slot="aui_message-group" as transcript height', () => {
|
||||
stubMeasuredRects()
|
||||
const { container } = render(
|
||||
<Harness withViewport>
|
||||
<div data-slot="aui_message-group">turn</div>
|
||||
</Harness>
|
||||
)
|
||||
|
||||
expect(bandHeight(container)).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('still measures slot-less direct children such as show-earlier', () => {
|
||||
stubMeasuredRects()
|
||||
const { container } = render(
|
||||
<Harness withViewport>
|
||||
<button type="button">Show earlier</button>
|
||||
</Harness>
|
||||
)
|
||||
|
||||
expect(bandHeight(container)).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('does not treat clearance or background-resume spacers as message rows', () => {
|
||||
stubMeasuredRects()
|
||||
const { container } = render(
|
||||
<Harness withViewport>
|
||||
<div data-slot="aui_background-resume">resume</div>
|
||||
<div data-slot="aui_composer-clearance" />
|
||||
</Harness>
|
||||
)
|
||||
|
||||
expect(bandHeight(container)).toBe(0)
|
||||
})
|
||||
|
||||
it('keeps an empty band when aui_thread-content is missing', () => {
|
||||
stubMeasuredRects()
|
||||
const { container } = render(<Harness withThreadContent={false} withViewport />)
|
||||
|
||||
expect(bandHeight(container)).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -49,7 +49,9 @@ export function useHudTranscriptBand(rootRef: RefObject<HTMLDivElement | null>):
|
||||
// rows only. Measuring to the viewport edge counted the full-window scroll
|
||||
// container (min-height: 100%) as transcript and painted a empty slab almost
|
||||
// the size of the HUD.
|
||||
const rows = el?.querySelectorAll<HTMLElement>('[data-slot="aui_thread-content"] > *:not([data-slot])')
|
||||
const rows = el?.querySelectorAll<HTMLElement>(
|
||||
'[data-slot="aui_thread-content"] > [data-slot="aui_message-group"], [data-slot="aui_thread-content"] > *:not([data-slot])'
|
||||
)
|
||||
|
||||
// Zero-height rows are not a transcript. A fresh thread still renders
|
||||
// scaffolding inside the content box (clearance, empty state), so
|
||||
|
||||
Reference in New Issue
Block a user