fix(tests): add requestAnimationFrame fallback for flaky Ubuntu CI tests

Add defensive runtime check in useXterm.ts to handle test environments
where requestAnimationFrame may not be defined. This fixes intermittent
CI failures on Ubuntu where the vitest node/jsdom environment switching
caused a race condition.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
AndyMik90
2026-01-17 00:23:26 +01:00
parent cb8e46ca2a
commit 9739b338bb
@@ -219,8 +219,13 @@ export function useXterm({ terminalId, onCommandEnter, onResize, onDimensionsRea
// Use requestAnimationFrame to wait for layout, then fit
// This is more reliable than a fixed timeout
// Fallback to setTimeout for test environments where requestAnimationFrame may not be defined
const raf = typeof requestAnimationFrame !== 'undefined'
? requestAnimationFrame
: (cb: FrameRequestCallback) => setTimeout(() => cb(Date.now()), 0) as unknown as number;
const performInitialFit = () => {
requestAnimationFrame(() => {
raf(() => {
if (fitAddonRef.current && xtermRef.current && terminalRef.current) {
// Check if container has valid dimensions
const rect = terminalRef.current.getBoundingClientRect();