diff --git a/e2e/policies-open.spec.ts b/e2e/policies-open.spec.ts index 6d6d8bc0..868a07b6 100644 --- a/e2e/policies-open.spec.ts +++ b/e2e/policies-open.spec.ts @@ -65,3 +65,21 @@ for (const viewport of [ await expectSteadyCards(page); }); }); + +// A card that opened on screen and was scrolled away before its group arrived stops waiting for it, so the list shows. +test('scrolling away from a loading card shows the list', async ({page}) => { + const {api} = await mockBackend(page); + const [first] = await api.groups(); + await page.route(new RegExp(`/api/v1/groups/${first.id}(\\?.*)?$`), async route => { + if (route.request().method() === 'GET') await new Promise(resolve => setTimeout(resolve, 15_000)); + await route.fallback(); + }); + await page.setViewportSize({width: 1440, height: 500}); + await page.goto('/#/policies'); + const list = page.locator('.rp-tabpanel[data-shown] .rp-policy-list'); + await expect(list).toHaveAttribute('data-wait', ''); + await page.mouse.move(720, 300); + for (let i = 0; i < 10; i++) await page.mouse.wheel(0, 1000); + await expect(page.getByRole('region', {name: first.name, exact: true})).not.toBeInViewport({ratio: 0}); + await expect(list).not.toHaveAttribute('data-wait', {timeout: 5_000}); +}); diff --git a/src/features/policies/Policies.tsx b/src/features/policies/Policies.tsx index 981a84f7..2e05d0de 100644 --- a/src/features/policies/Policies.tsx +++ b/src/features/policies/Policies.tsx @@ -108,15 +108,16 @@ function PolicyDetail(props: PolicyGroupInput) { const m = usePolicyGroup(props); const g = m.card; const gate = use(FirstShow); - const {id} = props; + const {id, paused} = props; + // A card scrolled away stops reading its group, so it no longer holds the list. useLayoutEffect(() => { - if (!m.loading) { + if (!m.loading || paused) { gate.release(id); return; } gate.hold(id); return () => gate.release(id); - }, [gate, id, m.loading]); + }, [gate, id, m.loading, paused]); return ( <>