fix(native-chat): keep a consistent gap above an answer's action row (#42942)

This commit is contained in:
Jinjing
2026-11-16 12:21:23 -07:00
committed by GitHub
parent 4a606f2899
commit 33b133601b
4 changed files with 118 additions and 3 deletions
@@ -21,8 +21,9 @@ export function NativeChatAgentControls({
}): React.JSX.Element {
const t = useTranslate()
return (
// Row chrome, not transcript: find skips it.
<div data-native-chat-find-skip className={cn('flex items-center gap-1', className)}>
// Row chrome, not transcript: find skips it. The row owns a minimum gap above it, so every answer
// gets at least this much: it collapses with the last block's bottom margin, and a larger one wins.
<div data-native-chat-find-skip className={cn('mt-3 flex items-center gap-1', className)}>
{/* A visual line means nothing pasted outside Orca, so the copy leaves it out. An image-only
response has nothing to copy, so it has no Copy. */}
{markdown.length > 0 ? (
@@ -0,0 +1,73 @@
import { defineFixture } from '../../../../component-fixtures/component-fixture'
import { NativeChatMessageList } from '../../NativeChatMessageList'
import type { NativeChatLiveSession } from '../../session/terminal/read/native-chat-live-session-contract'
import type { NativeChatMessage } from '../../../../../../shared/native-chat/native-chat-types'
import { NativeChatVisualOwnerContext } from '../../media/visuals/native-chat-visual-owner'
import {
NATIVE_CHAT_APPEARANCE_ROOT_CLASS,
nativeChatAppearanceStyle
} from '../../appearance/native-chat-appearance-style'
// Every answer keeps at least the same gap above its actions, whatever it ends with.
const owner = {
target: { kind: 'local' as const },
sessionId: 'actions-gap',
worktreeId: 'actions-gap'
}
const ORDER = ['ask', 'reply', 'check', 'last']
function message(id: string, role: NativeChatMessage['role'], text: string): NativeChatMessage {
return {
id,
role,
timestamp: 1_800_000_000_000 + ORDER.indexOf(id) * 60_000,
source: 'transcript',
blocks: [{ type: 'text', text }]
}
}
function ActionsGap({ last }: { last: string }): React.JSX.Element {
const session: NativeChatLiveSession = {
agent: 'claude',
sessionId: 'actions-gap',
status: 'ready',
readPhase: 'ready',
hasMore: false,
loadingEarlier: false,
olderHistoryGeneration: 0,
loadEarlier: async () => 'applied',
messages: [
message('ask', 'user', 'Anything new on the board?'),
message('reply', 'assistant', 'Two items moved to done.'),
message('check', 'user', 'Check again.'),
message('last', 'assistant', last)
]
}
const theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light'
return (
<NativeChatVisualOwnerContext.Provider value={owner}>
<div
className={`${NATIVE_CHAT_APPEARANCE_ROOT_CLASS} flex h-[420px] flex-col`}
style={nativeChatAppearanceStyle({ theme })}
>
<NativeChatMessageList session={session} isWorking={false} expandSignal={false} />
</div>
</NativeChatVisualOwnerContext.Provider>
)
}
export const paragraph = defineFixture({
width: 560,
render: () => <ActionsGap last="Nothing changed since the last check." />
})
export const list = defineFixture({
width: 560,
render: () => <ActionsGap last={'Two items moved:\n\n- Share dialog\n- Release notes'} />
})
export const code = defineFixture({
width: 560,
render: () => <ActionsGap last={'Run this:\n\n```sh\npnpm test\n```'} />
})
@@ -121,7 +121,7 @@ export function NativeChatAssistantMessageRow({
) : null
}
className={cn(
'mt-1 w-fit select-none',
'w-fit select-none',
!latestResponse &&
fork?.pendingItemId !== message.id &&
'transition-opacity can-hover:pointer-events-none can-hover:opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100',
@@ -0,0 +1,41 @@
import { expect, test, type Locator, type Page } from '@playwright/test'
// The visible gap between an answer's last block and its actions, at the default chat typography.
// Before the actions owned the gap, a paragraph got 4px and a list 10px.
test.use({ viewport: { width: 1000, height: 720 } })
const GAP = 12
// The block itself, not whichever inline element holds its text.
const LAST_BLOCK: Record<string, (page: Page) => Locator> = {
paragraph: (page) =>
page.getByRole('paragraph').filter({ hasText: 'Nothing changed since the last check.' }),
list: (page) => page.getByRole('listitem').filter({ hasText: 'Release notes' })
}
for (const [ending, lastBlock] of Object.entries(LAST_BLOCK)) {
test(`an answer ending in a ${ending} keeps a ${GAP}px gap above its actions`, async ({
page
}) => {
await page.goto(
`/fixtures.html?id=native-chat/messages/rows/NativeChatActionsGap:${ending}&theme=light`
)
// A cold server compiles the whole chat graph on first load.
await expect(page.locator('html')).toHaveAttribute('data-fixture-state', 'ready', {
timeout: 60_000
})
const earlier = page.getByText('Two items moved to done.', { exact: true })
await expect(earlier).toHaveCSS('font-size', '13px')
await expect(earlier).toHaveCSS('line-height', '20px')
const block = await lastBlock(page).boundingBox()
// The action the reader sees, not whatever box happens to wrap it.
const action = await page
.getByRole('button', { name: 'Scroll this message to top' })
.last()
.boundingBox()
if (!block || !action) {
throw new Error('The answer or its actions did not render')
}
expect(action.y - (block.y + block.height)).toBeCloseTo(GAP, 0)
})
}