Fix frame pacing

This commit is contained in:
2026-07-21 21:59:26 +10:00
parent 7d134ff8c9
commit db864af147
10 changed files with 202 additions and 22 deletions
+50
View File
@@ -160,6 +160,56 @@ describe('native router transactions', () => {
expect(native.entries.value.some((entry) => entry.route.path === '/right')).toBe(false)
})
it('prepares a newly mounted destination for a paint before animation can begin', async () => {
vi.mocked(window.matchMedia).mockReturnValue({ matches: false } as MediaQueryList)
let paint: FrameRequestCallback | undefined
vi.spyOn(window, 'requestAnimationFrame').mockImplementation((callback) => {
paint = callback
return 1
})
const { native } = await harness()
let resolved = false
const beginning = native.beginInteractive('push', '/b').then((id) => {
resolved = true
return id
})
await vi.waitFor(() => expect(paint).toBeTypeOf('function'))
expect(resolved).toBe(false)
expect(native.entries.value.find((entry) => entry.route.path === '/b')?.mounted).toBe(true)
paint?.(performance.now())
expect(await beginning).not.toBeNull()
vi.mocked(window.matchMedia).mockReturnValue({ matches: true } as MediaQueryList)
await native.cancelInteractive()
})
it('collapses pushed history when a tab replaces it with an existing root', async () => {
const { router, native } = await harness()
await native.push('/b')
expect(native.canGoBack.value).toBe(true)
await native.sibling('/a', { replace: true })
expect(router.currentRoute.value.path).toBe('/a')
expect(native.canGoBack.value).toBe(false)
expect(await native.beginInteractive('pop')).toBeNull()
})
it('manually unloads inactive route instances but never the active view', async () => {
const { native } = await harness()
await native.replace('/left', { presentation: 'none' })
await native.sibling('/middle', { replace: true })
expect(native.unload('/left')).toBe(1)
expect(native.entries.value.find((entry) => entry.route.path === '/left')).toMatchObject({
mounted: false,
evictionReason: 'manual',
})
expect(native.unload('/middle')).toBe(0)
expect(native.entries.value.find((entry) => entry.route.path === '/middle')?.mounted).toBe(true)
})
it('evicts the least-recently-used inactive view when the cache limit is exceeded', async () => {
let clock = 0
vi.spyOn(performance, 'now').mockImplementation(() => ++clock)