Skip to content

fix(hub-ui): wait for trust without a deadline before the messages fetch - #495

Merged
antfu merged 1 commit into
devframes:mainfrom
0froq:fix/hub-messages-trust-wait
Nov 18, 2026
Merged

antfu merged 1 commit into
devframes:mainfrom
0froq:fix/hub-messages-trust-wait

Conversation

@0froq

@0froq 0froq commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #440

Description

useMessages starts its initial feed fetch with context.rpc.ensureTrusted(), which runs on the default 60 second trust deadline. On an auth-enforcing host where the DevTools client is never authorized, that promise rejects and nothing handles it, so the rejection surfaces as an uncaught error while the app page itself still works.

The initial fetch does not need a deadline. ensureTrusted(0) returns the pending trust promise without one, and that promise still resolves through requestTrustWithCode, so a user who authorizes after 60 seconds gets the feed. Later trust changes already reach the feed through the existing devframe:messages:updated handler, which checks isTrusted.

Limitation: the trust promise settles once, so this covers the first authorization only. A revoke and re-authorize cycle does not re-run the initial fetch.

The alternative is subscribing to DEVFRAME_EVENTS.client.isTrustedUpdated and refreshing when it reports true. That would also refetch after re-authorization and matches the shape in messages-client.ts and context.ts. Three costs. Events do not replay, so a client trusted before the hub mounts needs an isTrusted check up front. The event fires false on revocation, so the handler needs a guard against refetching then. useMessages is a module singleton with no teardown, so the listener would live as long as the page. I chose the promise because "wait for the first trust" is what it already means. Easy to switch if you prefer the event path.

Test

Reference host examples/hub-vite (embedded hub UI, @devframes/plugin-messages mounted, interactive OTP gate on), page left unauthorized. Vite's client forwards unhandled rejections to the dev-server terminal, which is where these lines appear.

Before, on main:

  15:20:00 [vite] (client) [Unhandled rejection] Error: [devframe] Timeout waiting
for rpc to be trusted
  15:21:47 [vite] (client) [Unhandled rejection] Error: [devframe] Timeout waiting
for rpc to be trusted

Both landed 60 seconds after a page load.

After the change, the same page left unauthorized for 90 seconds logs nothing, and authorizing at that point still fills the feed.

There is also a focused case in packages/hub-ui/src/client/state/messages.test.ts. It holds the trust promise open, asserts the gate is entered without a deadline and that no list call happens yet, then resolves trust and asserts the fetch runs once. It fails on main with expected "vi.fn()" to be called with arguments: [ +0 ].

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.
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

@0froq is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/495?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-11-17 07:42 UTC
🔗 head 5bb47c9
🤖 automated by pulls.review

{
  "headSha": "5bb47c9accf308b8799e49c779267b13a2e6b86e",
  "result": {
    "overallSummary": "Fixes an uncaught rejection on auth-enforcing hosts: `useMessages`' initial feed fetch used to call `ensureTrusted()` with the default 60s deadline, which rejected with an unhandled error if the user hadn't authorized yet. The fix passes `0` to wait without a deadline, and a new test covers the gating behavior.",
    "groups": [
      {
        "key": "fix",
        "label": "Fix trust wait deadline",
        "summary": "Changes `useMessages` to call `ensureTrusted(0)` instead of the default call, so the initial feed fetch waits indefinitely for trust instead of rejecting with an unhandled error after the default 60s deadline on auth-enforcing hosts.",
        "category": "core",
        "filePaths": [
          "packages/hub-ui/src/client/state/messages.ts"
        ],
        "critical": true,
        "lineNotes": [
          {
            "path": "packages/hub-ui/src/client/state/messages.ts",
            "side": "additions",
            "line": 93,
            "text": "`ensureTrusted(0)` removes the timeout for this initial wait; later trust/revocation changes still flow through the existing `devframe:messages:updated` handler, so this only affects the first fetch."
          }
        ]
      },
      {
        "key": "tests",
        "label": "Trust wait test",
        "summary": "Adds a focused test asserting the initial fetch waits for trust without calling `call` until the trust promise resolves, and that `ensureTrusted` is invoked with `0` (no deadline).",
        "category": "tests",
        "filePaths": [
          "packages/hub-ui/src/client/state/messages.test.ts"
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-17T07:42:41.642Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

@antfu
antfu merged commit 9cb2bd0 into devframes:main Nov 18, 2026
13 of 15 checks passed
@0froq
0froq deleted the fix/hub-messages-trust-wait branch November 18, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hub-ui: background messages initialization produces an unhandled trust timeout after 60 seconds

2 participants