From 5bb47c9accf308b8799e49c779267b13a2e6b86e Mon Sep 17 00:00:00 2001 From: 0froq Date: Tue, 17 Nov 2026 14:44:47 +0800 Subject: [PATCH] fix(hub-ui): wait for trust without a deadline before the messages fetch Background message init ran on the default 60s trust deadline. A page whose DevTools client stays unauthorized then rejected with an uncaught timeout. The initial fetch needs no deadline: it must run whenever trust arrives. --- .../hub-ui/src/client/state/messages.test.ts | 32 +++++++++++++++++++ packages/hub-ui/src/client/state/messages.ts | 5 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/hub-ui/src/client/state/messages.test.ts b/packages/hub-ui/src/client/state/messages.test.ts index f2e19e97..05709542 100644 --- a/packages/hub-ui/src/client/state/messages.test.ts +++ b/packages/hub-ui/src/client/state/messages.test.ts @@ -83,6 +83,38 @@ it.each([false, true])('removes visible toasts and timers when the message is re expect(clearTimer).toHaveBeenCalledOnce() }) +it('waits for trust without a deadline before the initial fetch', async () => { + expect.assertions(3) + const { useMessages } = await import('./messages') + const trust = Promise.withResolvers() + const ensureTrusted = vi.fn(() => trust.promise) + const call = vi.fn(async () => ({ + entries: [], + removedIds: [], + version: 0, + full: true, + })) + // eslint-disable-next-line slop/no-chained-type-assertions -- Only the RPC trust gate and feed participate in this state test. + useMessages({ + rpc: { + call, + isTrusted: false, + ensureTrusted, + client: { + register: () => {}, + }, + }, + } as unknown as DocksContext) + + await Promise.resolve() + expect(ensureTrusted).toHaveBeenCalledWith(0) + expect(call).not.toHaveBeenCalled() + + trust.resolve(true) + await vi.waitUntil(() => call.mock.calls.length === 1) + expect(call).toHaveBeenCalledOnce() +}) + it('keeps surviving toasts and unread counts when receiving a full snapshot', async () => { expect.assertions(3) const { state, toasts, publish, message } = await fixture() diff --git a/packages/hub-ui/src/client/state/messages.ts b/packages/hub-ui/src/client/state/messages.ts index 7ceac85d..c29ebd4a 100644 --- a/packages/hub-ui/src/client/state/messages.ts +++ b/packages/hub-ui/src/client/state/messages.ts @@ -90,7 +90,10 @@ export function useMessages(context: DocksContext): Reactive { }, }) - context.rpc.ensureTrusted().then(() => refresh()) + // Background initialization waits for trust without a deadline. A page can + // stay untrusted while the user authorizes DevTools, and the default 60s + // deadline would only surface an unhandled rejection in the app. + context.rpc.ensureTrusted(0).then(() => refresh()) return state }