From 2d6f81be517ae5e1c9ba82e11c252f8a16501a18 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Sun, 8 Nov 2026 09:47:50 +0800 Subject: [PATCH 1/2] fix(web-ui): keep device previews visible while browsing --- .../src/app/components/NavPanel/NavPanel.scss | 4 +- .../components/DeviceStatusControl.test.tsx | 98 ++++++---- .../components/DeviceStatusControl.tsx | 9 +- .../components/useDevicePreviewMotion.ts | 181 +++++++----------- 4 files changed, 129 insertions(+), 163 deletions(-) diff --git a/src/web-ui/src/app/components/NavPanel/NavPanel.scss b/src/web-ui/src/app/components/NavPanel/NavPanel.scss index 39d4439ff5..5892bc0399 100644 --- a/src/web-ui/src/app/components/NavPanel/NavPanel.scss +++ b/src/web-ui/src/app/components/NavPanel/NavPanel.scss @@ -1582,7 +1582,9 @@ $_section-header-height: 22px; background: var(--openbitfun-color-surface-raised); // Switch state color once. Interpolating an inherited custom property forces // style recalculation throughout the card on every animation frame. - animation: openbitfun-nav-popover-in 150ms cubic-bezier(0.23, 1, 0.32, 1) both; + // Release the opening transform instead of retaining a transformed clipping + // ancestor around the independently moving device artwork. + animation: openbitfun-nav-popover-in 150ms cubic-bezier(0.23, 1, 0.32, 1) backwards; &[data-control-state='active'] { --_device-overview-light: var(--openbitfun-color-status-success-content); diff --git a/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.test.tsx b/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.test.tsx index 0c78f9ea79..f82ac6cca9 100644 --- a/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.test.tsx +++ b/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.test.tsx @@ -150,7 +150,7 @@ function installPreviewAnimations() { return { records, finishPhase: async () => { - const phase = records.slice(-3); + const phase = records.slice(-1); await act(async () => { phase.forEach(animation => animation.finish()); }); }, }; @@ -480,74 +480,92 @@ describe('device status card', () => { expect(element('device-sidebar-visibility').dataset.deviceSurface).toBe('local'); }); - it('hands off artwork, name, pagination and actions together without invoking the old device', async () => { + it('commits artwork, name, pagination and actions together without a blank exit', async () => { const { next } = await renderBrowseableDevices(); const motion = installPreviewAnimations(); const total = element('nav-device-status-total'); act(() => next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 }))); - expect(element('nav-device-status-name').textContent).toBe('Current host'); - expect(element('nav-device-status-pagination').textContent).toBe('2 / 4'); - expect((element('device-sidebar-visibility') as HTMLButtonElement).disabled).toBe(true); - act(() => { element('device-sidebar-visibility').click(); element('nav-device-usage-status').click(); }); - expect(state.disconnectDevice).not.toHaveBeenCalled(); - expect(motion.records).toHaveLength(3); - expect(motion.records.every(animation => !animation.element.contains(total))).toBe(true); - expect(motion.records[0].options.duration).toBe(80); - expect(motion.records[0].keyframes[1].transform).toBe('translateX(calc(4px * -1))'); - await motion.finishPhase(); + // The new device is usable before any animation completes. No stale action + // or disabled-color flash is needed to bridge an asynchronous content swap. expect(element('nav-device-status-name').textContent).toBe('Another host'); expect(element('nav-device-status-pagination').textContent).toBe('3 / 4'); expect(element('nav-device-status-total')).toBe(total); - expect(total.textContent).toBe('4'); expect(document.querySelector('[data-artwork="linux"]')).not.toBeNull(); expect(document.querySelector('[data-testid="nav-device-usage-status"]')).toBeNull(); - expect(motion.records).toHaveLength(6); - expect(motion.records[3].options.duration).toBe(140); - expect(motion.records[3].keyframes[0].transform).toBe('translateX(calc(4px * 2))'); - expect((element('device-sidebar-visibility') as HTMLButtonElement).disabled).toBe(true); - act(() => element('device-sidebar-visibility').click()); - expect(state.switchToDevice).not.toHaveBeenCalled(); - await motion.finishPhase(); expect((element('device-sidebar-visibility') as HTMLButtonElement).disabled).toBe(false); - await act(async () => element('device-sidebar-visibility').click()); + act(() => element('device-sidebar-visibility').click()); expect(useDeviceVisibilityPreferences.getState().hidden['peer-2']).toBe(true); + expect(useDeviceVisibilityPreferences.getState().hidden['peer-1']).toBeUndefined(); + + expect(motion.records).toHaveLength(1); + expect(motion.records[0].element.classList.contains('openbitfun-device-overview__device-scene')).toBe(true); + expect(motion.records[0].keyframes).toEqual([ + { transform: 'translateX(calc(4px * 2))' }, { transform: 'none' }, + ]); + expect(motion.records[0].options).toMatchObject({ duration: 140, fill: 'backwards' }); + await motion.finishPhase(); + expect(element('nav-device-status-name').textContent).toBe('Another host'); + expect(element('nav-device-status-popover').hasAttribute('data-preview-motion')).toBe(false); expect(state.switchToDevice).not.toHaveBeenCalled(); expect(state.disconnectDevice).not.toHaveBeenCalled(); }); - it('coalesces rapid clicks and interrupts an entrance from its current frame', async () => { + it('keeps rapid browsing current and ignores completions from interrupted motion', async () => { const { next, previous } = await renderBrowseableDevices(); const motion = installPreviewAnimations(); - const styles = vi.spyOn(globalThis, 'getComputedStyle'); - act(() => { next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 })); next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 })); }); - expect(motion.records).toHaveLength(3); - expect(styles).toHaveBeenCalledTimes(1); - await motion.finishPhase(); - expect(styles).toHaveBeenCalledTimes(1); - styles.mockRestore(); + act(() => { + next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 })); + next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 })); + }); + expect(motion.records).toHaveLength(1); expect(element('nav-device-status-name').textContent).toBe('Third host'); expect(element('nav-device-status-pagination').textContent).toBe('4 / 4'); expect(document.querySelector('[data-artwork="server"]')).not.toBeNull(); - const interrupted = motion.records.slice(-3); - const scene = motion.records[0].element; - scene.style.opacity = '0.35'; + const interrupted = motion.records[0]; + const scene = interrupted.element; scene.style.transform = 'translateX(2px)'; act(() => previous.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 }))); - expect(interrupted.every(animation => animation.cancel.mock.calls.length === 1)).toBe(true); - expect(motion.records[6].keyframes[0]).toEqual({ opacity: '0.35', transform: 'translateX(2px)' }); - scene.style.removeProperty('opacity'); + expect(interrupted.cancel).toHaveBeenCalledOnce(); + expect(element('nav-device-status-name').textContent).toBe('Another host'); + expect(motion.records[1].keyframes[0]).toEqual({ transform: 'translateX(2px)' }); scene.style.removeProperty('transform'); - await act(async () => { interrupted.forEach(animation => animation.finish()); }); - expect(element('nav-device-status-name').textContent).toBe('Third host'); - await motion.finishPhase(); + await act(async () => { interrupted.finish(); }); expect(element('nav-device-status-name').textContent).toBe('Another host'); + expect(element('nav-device-status-popover').dataset.previewMotion).toBe('true'); await motion.finishPhase(); - expect((element('device-sidebar-visibility') as HTMLButtonElement).disabled).toBe(false); + expect(element('nav-device-status-popover').hasAttribute('data-preview-motion')).toBe(false); expect(state.switchToDevice).not.toHaveBeenCalled(); }); + it('keeps the selected device usable if the browser cannot start an animation', async () => { + const { next } = await renderBrowseableDevices(); + installPreviewAnimations(); + const scene = document.querySelector('.openbitfun-device-overview__device-scene')!; + scene.animate = () => { throw new Error('Animation unavailable'); }; + act(() => next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 }))); + expect(element('nav-device-status-name').textContent).toBe('Another host'); + expect(element('nav-device-status-popover').hasAttribute('data-preview-motion')).toBe(false); + expect((element('device-sidebar-visibility') as HTMLButtonElement).disabled).toBe(false); + }); + + it('cancels decorative motion when the rendered device changes externally', async () => { + const { next } = await renderBrowseableDevices(); + const motion = installPreviewAnimations(); + act(() => next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 }))); + expect(element('nav-device-status-name').textContent).toBe('Another host'); + await act(async () => { + state.overview = overview(); + render(); + }); + expect(element('nav-device-status-name').textContent).toBe('Workstation'); + expect(motion.records[0].cancel).toHaveBeenCalledOnce(); + await motion.finishPhase(); + expect(element('nav-device-status-name').textContent).toBe('Workstation'); + expect(element('nav-device-status-popover').hasAttribute('data-preview-motion')).toBe(false); + }); + it('settles directly when reduced motion is preferred or enabled during a transition', async () => { const setReduced = installMotionPreference(true); const { next } = await renderBrowseableDevices(); @@ -557,7 +575,7 @@ describe('device status card', () => { expect(element('nav-device-status-name').textContent).toBe('Another host'); setReduced(false); act(() => next.dispatchEvent(new MouseEvent('click', { bubbles: true, detail: 1 }))); - expect(motion.records).toHaveLength(3); + expect(motion.records).toHaveLength(1); setReduced(true); expect(element('nav-device-status-name').textContent).toBe('Third host'); expect((element('device-sidebar-visibility') as HTMLButtonElement).disabled).toBe(false); diff --git a/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.tsx b/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.tsx index 0f8b5f4902..11492f121d 100644 --- a/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.tsx +++ b/src/web-ui/src/app/components/NavPanel/components/DeviceStatusControl.tsx @@ -229,8 +229,6 @@ const DeviceStatusControl: React.FC = ({ const triggerRef = useRef(null); const popoverRef = useRef(null); const artworkRef = useRef(null); - const headingRef = useRef(null); - const actionsRef = useRef(null); const selectPreview = useCallback((deviceId: string) => { setPreviewId(deviceId); }, []); @@ -238,8 +236,6 @@ const DeviceStatusControl: React.FC = ({ scope: JSON.stringify([open, accountId, activePeerId, carouselDeviceIds]), surfaceRef: popoverRef, artworkRef, - headingRef, - actionsRef, onSelect: selectPreview, }); const browseDevice = (direction: -1 | 1, animate: boolean) => { @@ -546,7 +542,7 @@ const DeviceStatusControl: React.FC = ({ {formatNumber(previewDevices.length)} )} -
+
{/* The system is drawn, not written: the same mark the trigger and the device rows use. State is drawn after the name. */}
-
+
{displayedSurfaceId && !['mobile', 'watch'].includes(displayedAccountDevice?.device_kind?.trim().toLowerCase() ?? '') && ( )}
diff --git a/src/web-ui/src/app/components/NavPanel/components/useDevicePreviewMotion.ts b/src/web-ui/src/app/components/NavPanel/components/useDevicePreviewMotion.ts index 0236723013..cbf2973f1e 100644 --- a/src/web-ui/src/app/components/NavPanel/components/useDevicePreviewMotion.ts +++ b/src/web-ui/src/app/components/NavPanel/components/useDevicePreviewMotion.ts @@ -5,151 +5,102 @@ interface DevicePreviewMotionOptions { scope: string; surfaceRef: RefObject; artworkRef: RefObject; - headingRef: RefObject; - actionsRef: RefObject; onSelect: (deviceId: string) => void; } -interface PreviewTarget { - deviceId: string; - direction: -1 | 1; -} - -function readDuration(style: CSSStyleDeclaration, token: string): number { - const value = style.getPropertyValue(token).trim(); - const duration = Number.parseFloat(value) * (value.endsWith('ms') ? 1 : 1000); - return Number.isFinite(duration) && duration > 0 ? duration : 0; +interface PreviewEntrance { + scope: string; + transform: string; + duration: number; + easing: string; } -/** Manual browsing owns motion; hydration and surface changes always settle directly. */ +/** + * Commit the device in one render, then move only its artwork. Fading the old + * scene to zero before committing left a blank frame and mutated masked artwork, + * text and button paint underneath retained opacity animations in WebKit. + */ export function useDevicePreviewMotion({ - scope, surfaceRef, artworkRef, headingRef, actionsRef, onSelect, + scope, surfaceRef, artworkRef, onSelect, }: DevicePreviewMotionOptions) { - const [isTransitioning, setIsTransitioning] = useState(false); - const [entrance, setEntrance] = useState<{ target: PreviewTarget; generation: number } | null>(null); - const animationsRef = useRef([]); - const generationRef = useRef(0); - const phaseRef = useRef<'idle' | 'exit' | 'enter'>('idle'); - const pendingTargetRef = useRef(null); - const previousScopeRef = useRef(scope); + const [entrance, setEntrance] = useState(null); + const animationRef = useRef(null); + const pendingDeviceRef = useRef(null); - const cancelAnimations = useCallback(() => { - generationRef.current += 1; - animationsRef.current.forEach(animation => animation.cancel()); - animationsRef.current = []; + const cancelAnimation = useCallback(() => { + const animation = animationRef.current; + animationRef.current = null; + animation?.cancel(); }, []); - const settle = useCallback((selectPending: boolean) => { - const target = pendingTargetRef.current; - cancelAnimations(); - pendingTargetRef.current = null; - phaseRef.current = 'idle'; + const settle = useCallback(() => { + cancelAnimation(); + pendingDeviceRef.current = null; setEntrance(null); - setIsTransitioning(false); - if (selectPending && target) onSelect(target.deviceId); - }, [cancelAnimations, onSelect]); - - const readMotion = useCallback(() => { - const surface = surfaceRef.current; - // Pagination is visually hidden; it only needs the new accessible text. - const elements = [artworkRef.current, headingRef.current, actionsRef.current] - .filter((element): element is HTMLElement => element !== null); - if (!surface || isReducedMotionPreferred() || elements.length !== 3 - || elements.some(element => typeof element.animate !== 'function')) return null; - const style = getComputedStyle(surface); - const exitDuration = readDuration(style, '--openbitfun-motion-duration-instant'); - const enterDuration = readDuration(style, '--openbitfun-motion-duration-fast'); - const easing = style.getPropertyValue('--openbitfun-motion-easing-standard').trim(); - const distance = style.getPropertyValue('--openbitfun-motion-distance-sm').trim(); - if (!exitDuration || !enterDuration || !easing || !distance) return null; - return { elements, exitDuration, enterDuration, easing, distance }; - }, [actionsRef, artworkRef, headingRef, surfaceRef]); - const motionRef = useRef>(null); + }, [cancelAnimation]); const navigateTo = useCallback((deviceId: string, direction: -1 | 1, animate = true) => { - pendingTargetRef.current = { deviceId, direction }; - if (!animate || isReducedMotionPreferred()) { settle(true); return; } - // Repeated clicks during the short exit only change its destination. - // Do this before any style read, so a burst of clicks cannot force layout. - if (phaseRef.current === 'exit') return; - const motion = readMotion(); - if (!motion) { settle(true); return; } - motionRef.current = motion; - - // Interrupted entrances leave from their actual frame, without snapping back. - const starts = motion.elements.map(element => { - if (phaseRef.current !== 'enter') return { opacity: '1', transform: 'none' }; - const style = getComputedStyle(element); - return { opacity: style.opacity || '1', transform: style.transform || 'none' }; - }); - cancelAnimations(); - const generation = generationRef.current; - phaseRef.current = 'exit'; - setEntrance(null); - setIsTransitioning(true); - try { - motion.elements.forEach((element, index) => animationsRef.current.push(element.animate([ - starts[index], - { opacity: 0, transform: element === artworkRef.current - ? `translateX(calc(${motion.distance} * ${-direction}))` : 'none' }, - ], { duration: motion.exitDuration, easing: motion.easing, fill: 'forwards' }))); - void Promise.all(animationsRef.current.map(animation => animation.finished)).then(() => { - const target = pendingTargetRef.current; - if (generation !== generationRef.current || !target) return; - phaseRef.current = 'enter'; - onSelect(target.deviceId); - setEntrance({ target, generation }); - }).catch(() => { - if (generation === generationRef.current) settle(true); - }); - } catch { - settle(true); + let nextEntrance: PreviewEntrance | null = null; + const surface = surfaceRef.current; + const artwork = artworkRef.current; + if (animate && !isReducedMotionPreferred() && surface && artwork + && typeof artwork.animate === 'function') { + const style = getComputedStyle(surface); + const value = style.getPropertyValue('--openbitfun-motion-duration-fast').trim(); + const duration = Number.parseFloat(value) * (value.endsWith('ms') ? 1 : 1000); + const easing = style.getPropertyValue('--openbitfun-motion-easing-standard').trim(); + const distance = style.getPropertyValue('--openbitfun-motion-distance-sm').trim(); + if (Number.isFinite(duration) && duration > 0 && easing && distance) { + // Retarget rapid browsing from the visible position, before cancellation. + const transform = animationRef.current + ? getComputedStyle(artwork).transform + : `translateX(calc(${distance} * ${direction * 2}))`; + nextEntrance = { scope, transform, duration, easing }; + } } - }, [artworkRef, cancelAnimations, onSelect, readMotion, settle]); + cancelAnimation(); + pendingDeviceRef.current = deviceId; + // Content and controls change together, without waiting on animation.finished. + onSelect(deviceId); + setEntrance(nextEntrance); + }, [artworkRef, cancelAnimation, onSelect, scope, surfaceRef]); - useLayoutEffect(() => { - if (previousScopeRef.current === scope) return; - previousScopeRef.current = scope; - settle(false); - }, [scope, settle]); + useLayoutEffect(() => { settle(); }, [scope, settle]); + + useLayoutEffect(() => { pendingDeviceRef.current = null; }); useLayoutEffect(() => { - if (!entrance || entrance.generation !== generationRef.current) return; - // Reuse the parameters read before exit. Reading styles after swapping the - // artwork would synchronously flush its new layout in the hand-off frame. - const motion = motionRef.current; - if (!motion || isReducedMotionPreferred()) { settle(true); return; } - cancelAnimations(); - const generation = generationRef.current; + if (!entrance || entrance.scope !== scope) return; + const artwork = artworkRef.current; + if (!artwork || isReducedMotionPreferred()) { settle(); return; } try { - motion.elements.forEach(element => animationsRef.current.push(element.animate([ - { opacity: 0, transform: element === artworkRef.current - ? `translateX(calc(${motion.distance} * ${entrance.target.direction * 2}))` : 'none' }, - { opacity: 1, transform: 'none' }, - ], { duration: motion.enterDuration, easing: motion.easing, fill: 'both' }))); - void Promise.all(animationsRef.current.map(animation => animation.finished)).then(() => { - if (generation === generationRef.current) settle(false); - }).catch(() => { - if (generation === generationRef.current) settle(true); - }); + const animation = artwork.animate([ + { transform: entrance.transform }, + { transform: 'none' }, + ], { duration: entrance.duration, easing: entrance.easing, fill: 'backwards' }); + animationRef.current = animation; + const finish = () => { + if (animationRef.current === animation) settle(); + }; + void animation.finished.then(finish, finish); } catch { - settle(true); + settle(); } - }, [artworkRef, cancelAnimations, entrance, settle]); + }, [artworkRef, entrance, scope, settle]); useEffect(() => { const preference = globalThis.matchMedia?.('(prefers-reduced-motion: reduce)'); if (!preference) return; - const finish = () => { if (preference.matches) settle(true); }; + const finish = () => { if (preference.matches) settle(); }; preference.addEventListener('change', finish); return () => preference.removeEventListener('change', finish); }, [settle]); - useEffect(() => () => { cancelAnimations(); }, [cancelAnimations]); + useEffect(() => () => { cancelAnimation(); }, [cancelAnimation]); return { navigateTo, - isTransitioning, - pendingDeviceId: () => pendingTargetRef.current?.deviceId ?? null, + isTransitioning: entrance !== null && entrance.scope === scope, + pendingDeviceId: () => pendingDeviceRef.current, }; } From 8e8bb4f788e581ca7942ff583447ca1b52d624c1 Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Sun, 8 Nov 2026 09:53:11 +0800 Subject: [PATCH 2/2] fix(ui): align grouped file edits with individual tool cards --- .../conversation/FileRevisionSummary.module.css | 15 +++++++++++++++ .../conversation/FileRevisionSummary.tsx | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.module.css b/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.module.css index 0ee858144c..71b19231a2 100644 --- a/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.module.css +++ b/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.module.css @@ -66,6 +66,7 @@ color: var(--openbitfun-color-content-primary); font-family: var(--openbitfun-type-body-sm-font-family); font-size: var(--openbitfun-type-body-sm-font-size); + font-variant-numeric: proportional-nums; font-weight: var(--openbitfun-type-body-sm-font-weight); line-height: var(--openbitfun-type-body-sm-line-height); text-align: start; @@ -81,13 +82,27 @@ position: relative; display: inline-flex; flex: 0 0 auto; + /* Match the prominent tool card's leading slot, including the hover glyph. */ + inline-size: var(--openbitfun-space-5); + block-size: var(--openbitfun-space-5); + min-inline-size: var(--openbitfun-font-size-xl); + min-block-size: var(--openbitfun-font-size-xl); + align-items: center; + justify-content: center; color: var(--openbitfun-color-content-secondary); } + .icon [data-openbitfun-component='icon'] { + inline-size: var(--openbitfun-font-size-xl); + block-size: var(--openbitfun-font-size-xl); + } + .disclosure { position: absolute; inset: 0; display: inline-flex; + align-items: center; + justify-content: center; opacity: 0; background: var(--openbitfun-color-surface-panel); } diff --git a/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.tsx b/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.tsx index 0901512381..40313de870 100644 --- a/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.tsx +++ b/design-system/packages/ui/src/flow-chat/conversation/FileRevisionSummary.tsx @@ -42,8 +42,8 @@ export function FileRevisionSummary({ file, itemCount, expanded, onToggle, conte - {prefixLabel && {prefixLabel}} - {file.label} + {prefixLabel && {prefixLabel}} + {file.label} {(file.status || file.statusLabel || (!expanded && file.changeSummary)) && {(file.status || file.statusLabel) &&