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 }