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:
@@ -219,8 +219,13 @@ export function useXterm({ terminalId, onCommandEnter, onResize, onDimensionsRea
|
|||||||
|
|
||||||
// Use requestAnimationFrame to wait for layout, then fit
|
// Use requestAnimationFrame to wait for layout, then fit
|
||||||
// This is more reliable than a fixed timeout
|
// 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 = () => {
|
const performInitialFit = () => {
|
||||||
requestAnimationFrame(() => {
|
raf(() => {
|
||||||
if (fitAddonRef.current && xtermRef.current && terminalRef.current) {
|
if (fitAddonRef.current && xtermRef.current && terminalRef.current) {
|
||||||
// Check if container has valid dimensions
|
// Check if container has valid dimensions
|
||||||
const rect = terminalRef.current.getBoundingClientRect();
|
const rect = terminalRef.current.getBoundingClientRect();
|
||||||
|
|||||||
Reference in New Issue
Block a user