Handle interrupted navigation transitions

This commit is contained in:
2026-10-05 19:25:41 -04:00
parent 2670f3b701
commit f20cfe1300
2 changed files with 34 additions and 7 deletions
+23
View File
@@ -0,0 +1,23 @@
import { afterEach, expect, it, vi } from 'vitest';
import { enableViewTransitions } from '../../src/lib/ui/motion/viewTransition.js';
afterEach(() => vi.unstubAllGlobals());
it('allows navigation to continue when a transition is skipped or superseded', async () => {
let finish: () => void = () => {};
const finished = new Promise<void>(resolve => { finish = resolve; });
const complete = Promise.reject(new Error('navigation aborted'));
vi.stubGlobal('document', { startViewTransition: (update: () => Promise<void>) => {
void update().then(finish);
return { ready: Promise.reject(new DOMException('Skipped transition', 'AbortError')), finished };
} });
await enableViewTransitions({ complete });
await finished;
});
it('continues without animation when the browser cannot start a transition', async () => {
vi.stubGlobal('document', { startViewTransition: () => { throw new Error('Unavailable'); } });
await enableViewTransitions({ complete: Promise.resolve() });
vi.stubGlobal('document', {});
expect(enableViewTransitions({ complete: Promise.resolve() })).toBeUndefined();
});