Skip to content

mobile-bridge: native requests hang until the timeout when postMessage fails #7350

Description

@k0d3r1s

Summary

In the injected mobile bridge script, post() swallows any exception from postMessage, and request() registers its pending entry anyway. When the bridge is gone (for example during a navigation), the page's promise waits the full 10 s (30 s for clipboard requests) and then fails with "native request timed out". It should fail at once.

Repro

Code path (found by reading main):

  1. In a mobile WebView, call native.request(...) while window.ReactNativeWebView.postMessage throws, for example while the page navigates.
  2. post() catches the exception and returns nothing.
  3. request() has already stored the pending entry and started its timer. Nothing rejects it until the timer fires.

Cause

Line numbers are from main at 7c1353d8.

  • packages/mobile-bridge/src/inject.ts:63-69: post catches the error and returns nothing.
  • inject.ts:143-153: request creates the timer (:146-149), stores pending[id] (:150), then calls post (:151) and ignores the outcome.

Suggested fix

Make post return a boolean. In request, if post returns false, clear the timer, delete the pending entry and reject at once.

var post = function (message) {
  try {
    window.ReactNativeWebView.postMessage(JSON.stringify(message));
    return true;
  } catch (error) {
    return false;
  }
};

// in request():
if (!post({ type: "request", id: id, request: { kind: kind, payload: payload } })) {
  clearTimeout(timer);
  delete pending[id];
  reject(new Error("native bridge unavailable"));
}

Tested locally with a regression test.

Activity

  1. added theissue type on Nov 10, 2026
  2. added
    mobile
    confirmed-repro
    on Nov 10, 2026
  3. bb-slop-cop commented on Nov 10, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Medium priority · Low effort. Applied labels: mobile, confirmed-repro.
    • Verdict: REPRODUCED; high root-cause confidence. The same agent repeated the reproduction in a second clean trusted checkout.
    • Root cause: request/reply sends swallow synchronous transport errors, leaving their pending promises and 10/30-second deadlines active after delivery fails.
    • Reproduction report includes the runnable observer, failing regression, and verification evidence. Device navigation itself was not tested.
    • Ready fix: PR #7372 rejects failed sends immediately and clears pending state without changing the public bridge protocol. Two files, 47 changed text lines.
    • Verification: both regression cases fail before the fix and pass afterward; all 42 package tests, typecheck, type-aware lint, formatting, and git diff --check pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-repromobile

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions