Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/approval-reader-browser-smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ try {
await page.goto("http://127.0.0.1:" + server.address().port);
await expect.poll(() => requests.length).toBe(1);
await page.waitForTimeout(100);
const now = new Date();
await page.clock.install({ time: now });
await page.clock.pauseAt(new Date(now.getTime() + 1000));
const before = requests.length;
holdNext = true;
await page.evaluate(() => window.refresh());
Expand All @@ -95,6 +98,12 @@ try {
"Notifications must not cancel and restart a slow approval read",
);
assert.equal(aborted, 0);
const loading = page.getByText("Loading approval updates…");
await page.clock.runFor(1999);
await expect(loading).toHaveCount(0);
await page.clock.runFor(1);
await expect(loading).toBeVisible();
await page.clock.resume();
held.shift()();
await expect.poll(() => requests.length).toBe(before + 2);
holdNext = true;
Expand Down
13 changes: 12 additions & 1 deletion src/client/Approvals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ export function Approvals({
failure,
busy: readPending,
} = useCollectionRead(readKey);
const refreshing = readPending && snapshot?.key === readKey;
const [slowRefreshKey, setSlowRefreshKey] = useState<string>();
useEffect(() => {
if (!refreshing) return;
const timer = setTimeout(() => setSlowRefreshKey(readKey), 2000);
return () => {
clearTimeout(timer);
setSlowRefreshKey(undefined);
};
}, [refreshing, readKey]);
const rateLimited = isRateLimited(failure);
const readError = rateLimited ? "" : failureMessage;
const [selected, setSelected] = useState<Approval | null>(null);
Expand Down Expand Up @@ -294,7 +304,8 @@ export function Approvals({
{notice}
</p>
)}
{(readPending || !!failure) && (
{((readPending && (!refreshing || slowRefreshKey === readKey)) ||
!!failure) && (
<p
className={readError ? "error" : "field-hint"}
role={readError ? "alert" : "status"}
Expand Down