Skip to content

Commit 9cb2bd0

Browse files
authored
fix(hub-ui): wait for trust without a deadline before the messages fetch (#495)
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.
1 parent 50a0147 commit 9cb2bd0

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎packages/hub-ui/src/client/state/messages.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,38 @@ it.each([false, true])('removes visible toasts and timers when the message is re
8383
expect(clearTimer).toHaveBeenCalledOnce()
8484
})
8585

86+
it('waits for trust without a deadline before the initial fetch', async () => {
87+
expect.assertions(3)
88+
const { useMessages } = await import('./messages')
89+
const trust = Promise.withResolvers<boolean>()
90+
const ensureTrusted = vi.fn(() => trust.promise)
91+
const call = vi.fn(async () => ({
92+
entries: [],
93+
removedIds: [],
94+
version: 0,
95+
full: true,
96+
}))
97+
// eslint-disable-next-line slop/no-chained-type-assertions -- Only the RPC trust gate and feed participate in this state test.
98+
useMessages({
99+
rpc: {
100+
call,
101+
isTrusted: false,
102+
ensureTrusted,
103+
client: {
104+
register: () => {},
105+
},
106+
},
107+
} as unknown as DocksContext)
108+
109+
await Promise.resolve()
110+
expect(ensureTrusted).toHaveBeenCalledWith(0)
111+
expect(call).not.toHaveBeenCalled()
112+
113+
trust.resolve(true)
114+
await vi.waitUntil(() => call.mock.calls.length === 1)
115+
expect(call).toHaveBeenCalledOnce()
116+
})
117+
86118
it('keeps surviving toasts and unread counts when receiving a full snapshot', async () => {
87119
expect.assertions(3)
88120
const { state, toasts, publish, message } = await fixture()

‎packages/hub-ui/src/client/state/messages.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export function useMessages(context: DocksContext): Reactive<MessagesState> {
9090
},
9191
})
9292

93-
context.rpc.ensureTrusted().then(() => refresh())
93+
// Background initialization waits for trust without a deadline. A page can
94+
// stay untrusted while the user authorizes DevTools, and the default 60s
95+
// deadline would only surface an unhandled rejection in the app.
96+
context.rpc.ensureTrusted(0).then(() => refresh())
9497
return state
9598
}
9699

0 commit comments

Comments
 (0)