Skip to content

Commit 8d0ce17

Browse files
committed
fix(overlay): only confirm a wake when every report went out
If a report push fails during a wake, the page no longer tells the server it is synced, so the agent call waits for the bounded timeout instead of reading an old report. Refs #342
1 parent c0fb06d commit 8d0ce17

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎packages/devtools/src/__tests__/delta-channel.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,22 @@ describe('page lease', () => {
176176
lease.stop();
177177
});
178178

179+
it('does not say it is synced when a wake push fails', async () => {
180+
const { my, emit, calls } = rpc(false);
181+
const wake = vi.fn(async () => {
182+
throw new Error('push failed');
183+
});
184+
const lease = createPageLease(my, 'p1', { wake });
185+
await lease.refresh();
186+
emit('page-interest-changed', { watching: true });
187+
await vi.waitFor(() => expect(wake).toHaveBeenCalledTimes(1));
188+
await new Promise((resolve) => setTimeout(resolve, 20));
189+
expect(
190+
calls.some((c) => c.name === 'page-interest' && (c.arg as { synced?: boolean })?.synced),
191+
).toBe(false);
192+
lease.stop();
193+
});
194+
179195
it('asks again while idle, in case it missed the server', async () => {
180196
vi.useFakeTimers();
181197
const { my, calls } = rpc(false);

‎packages/devtools/src/overlay.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ async function startOverlay(options: OverlayOptions, own: (cleanup: () => void)
441441
// Wakes up with a push of every leased report when a panel or an agent looks again.
442442
const lease = createPageLease(my, pageId, {
443443
wake: () =>
444-
Promise.allSettled([
444+
Promise.all([
445445
on.components && pushTree(true),
446446
on.injectors && pushInjectorTree(true),
447447
on.components && cd?.push(false, true),

‎packages/devtools/src/page-lease.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export function createPageLease(my: Rpc, pageId: string, options: PageLeaseOptio
5353
try {
5454
await options.wake();
5555
} catch {
56-
// A failed push resyncs on its own; the server still hears the page is awake.
56+
// A report failed, so the server may still hold an old one. Leave its
57+
// wait to time out rather than say the page is synced.
58+
return;
5759
}
5860
await my.rpc.call('page-interest', { pageId, synced: true }).catch(() => {});
5961
})().finally(() => {

0 commit comments

Comments
 (0)