fix(cloud-create): repository row placeholder only after 150 ms, named 'Repository' for screen readers (design-squad on PC-4)

This commit is contained in:
Neil
2026-11-10 19:59:51 -08:00
parent e4283fd41d
commit c7e7a52d76
3 changed files with 81 additions and 5 deletions
@@ -0,0 +1,45 @@
// @vitest-environment happy-dom
import { act, cleanup, render } from '@testing-library/react'
import { afterEach, expect, it, vi } from 'vitest'
import type { Translate } from '@/i18n/use-translate'
import { VmBuildStepRow } from './VmBuildStepRow'
import type { VmBuildStep } from './vm-build-steps'
afterEach(() => {
cleanup()
vi.useRealTimers()
})
const t: Translate = (_key, fallback) => fallback
const pendingClone = (cloneMode?: 'clone' | 'update'): VmBuildStep => ({
id: 'clone',
state: 'pending',
skipped: false,
elapsedMs: null,
percent: null,
startedAt: null,
...(cloneMode ? { cloneMode } : {})
})
it('names the repository row once: no label guessed, a placeholder only after 150 ms (PC-4)', () => {
vi.useFakeTimers()
const row = (step: VmBuildStep) => (
<ol>
<VmBuildStepRow step={step} cloud detail={null} timing={null} t={t} />
</ol>
)
const { container, rerender } = render(row(pendingClone()))
// Accessible name only; no visible label, no placeholder yet (the plan usually answers by now).
expect(container.textContent).toContain('Repository')
expect(container.textContent).not.toContain('Clone repository')
expect(container.querySelector('[data-slot="skeleton"]')).toBeNull()
act(() => {
vi.advanceTimersByTime(160)
})
expect(container.querySelector('[data-slot="skeleton"]')).not.toBeNull()
// The plan answers: the one label, never changed afterwards.
rerender(row(pendingClone('update')))
expect(container.querySelector('[data-slot="skeleton"]')).toBeNull()
expect(container.textContent).toContain('Update repository')
})
@@ -10,6 +10,22 @@ import { typicalStepSeconds, type VmBuildStepTiming } from './vm-build-timing'
import { formatElapsedTime } from './worktree-creation-clock'
import { stepLabel, stepStateLabel } from './vm-build-sheet-copy'
/** The boot plan usually answers within this; only a slower answer shows the placeholder. */
const PLACEHOLDER_DELAY_MS = 150
/** True once `active` has held for `delayMs` (the row's mode is unknown only once per create). */
function useDelayedFlag(active: boolean, delayMs: number): boolean {
const [due, setDue] = React.useState(false)
React.useEffect(() => {
if (!active) {
return
}
const timer = window.setTimeout(() => setDue(true), delayMs)
return () => window.clearTimeout(timer)
}, [active, delayMs])
return active && due
}
/** One timed row of the build checklist; the failure card, not the row, carries the red. */
export function VmBuildStepRow({
step,
@@ -30,6 +46,8 @@ export function VmBuildStepRow({
// A live percent already says how far along the step is.
const hint = step.state === 'running' && step.percent === null ? timing : null
const slow = hint !== null && step.elapsedMs !== null && step.elapsedMs > hint.p95Ms
const modeUnknown = cloud && step.id === 'clone' && step.state === 'pending' && !step.cloneMode
const placeholderDue = useDelayedFlag(modeUnknown, PLACEHOLDER_DELAY_MS)
return (
<li
@@ -49,11 +67,23 @@ export function VmBuildStepRow({
(step.state === 'pending' || step.skipped) && 'text-muted-foreground'
)}
>
{cloud && step.id === 'clone' && step.state === 'pending' && !step.cloneMode ? (
// Clone or update is decided in a moment (boot plan); a placeholder never relabels.
{modeUnknown ? (
// Clone or update is decided in a moment (boot plan): a placeholder, never a guessed label.
// Usually decided within ~150 ms, so the placeholder shows only after that (no blink).
<>
<Skeleton className="inline-block h-3 w-28 align-middle" />
<span className="sr-only">{stepLabel(step, cloud, t)}</span>
<span className="sr-only">
{t(
'auto.components.worktree.creation.VmBuildSheet.repositoryPending',
'Repository'
)}
</span>
{placeholderDue ? (
<Skeleton className="inline-block h-3 w-28 align-middle" />
) : (
<span aria-hidden className="invisible">
{'\u00a0'}
</span>
)}
</>
) : (
stepLabel(step, cloud, t)
+2 -1
View File
@@ -4240,7 +4240,8 @@
"cloneDownload": "Downloading history…",
"cloneCounting": "Counting objects…",
"updateCloud": "Update repository",
"updateFetching": "Fetching changes…"
"updateFetching": "Fetching changes…",
"repositoryPending": "Repository"
},
"VmBuildFailureCard": {
"createFailedTitle": "Couldn’t create workspace",