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
32 changes: 32 additions & 0 deletions packages/hub-ui/src/client/state/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>()
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()
Expand Down
5 changes: 4 additions & 1 deletion packages/hub-ui/src/client/state/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export function useMessages(context: DocksContext): Reactive<MessagesState> {
},
})

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
}

Expand Down
Loading