← reports

#6455 · Focused browser routing from global plugin surfaces

BugMedium priorityMedium effortui · pluginsGitHub issue2026-10-28 · base 1a4a1d254c7b1f70d340ef9c800dad77dbeb8e66

Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro

1. TL;DR

Global plugin navigation does not receive the browser callback owned by the active content panel. With the in-app browser preference enabled and a desktop browser bridge present, a sibling sidebar link fails to open a browser tab, while the identical navigation from inside the panel succeeds. The router treats a missing local React context callback as browser unavailability even though a focused panel can open one. A focused DOM regression test reproduced this twice on the same trusted main commit in separate clean checkouts. This is a navigation-dispatch defect, not a layout or screenshot discrepancy; native macOS launch behavior was not exercised.

2. Claims vs findings

ClaimFindingEvidence
Sidebar plugin navigation ignores the in-app preference.Verified at the navigation owner boundaryThe real useBbNavigate → AppNavigationUrlHost path never calls the focused panel's openTab callback for its sibling sidebar button.
Navigation inside a content panel works.VerifiedThe same table-driven test passes for a link nested under UrlOpenRoutingProvider; disabling the preference invokes the external bridge.
A missing context makes the router regard the browser as unavailable.VerifiedThe source explicitly requires a non-null local callback as well as a desktop bridge.
The released macOS app launches a specific system browser in the reported remote setup.Not directly verifiedLinux jsdom with a stub desktop bridge, not a physical macOS desktop or remote server.

3. Environment

4. Minimal reproduction

  1. Use Node 22 and the repository's pinned pnpm version.
  2. Clone and build trusted main at the recorded commit:
    WORK=$(mktemp -d)
    git clone https://github.com/get-bb/bb.git "$WORK/source"
    cd "$WORK/source"
    git checkout --detach 1a4a1d254c7b1f70d340ef9c800dad77dbeb8e66
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
    # Save the linked reproduction artifact as apps/app/src/lib/url-open-routing.sidebar.test.tsx
    pnpm exec turbo run test --filter=@bb/app -- src/lib/url-open-routing.sidebar.test.tsx
  3. Download the authored regression file and put it at the path shown before the final command.
  4. The harness renders a global navigation host, a sibling sidebar plugin, and a focused browser-capable panel. Both links use the production plugin-navigation hook. Only the desktop bridge and tab/reveal side effects are test doubles.

Expected: both navigation surfaces call openTab({ kind: "browser", url: "https://example.com/review" }), reveal the panel, and avoid the external browser while the preference is enabled.

Actual, both clean runs:

FAIL opens sidebar plugin links in the focused panel and respects the preference
AssertionError: expected "vi.fn()" to be called with arguments: [ { kind: 'browser', …(1) } ]
Number of calls: 0
FAIL falls back externally when the focused browser loses focus or unmounts
AssertionError: expected "vi.fn()" to be called once, but got 0 times
Test Files  1 failed (1)
Tests  2 failed | 1 passed (3)

The passing case is the panel-local link. The lifecycle test fails at its initial sidebar-open assertion, before reaching its focus-loss or unmount assertions; those later assertions are fix requirements, not baseline observations.

Complete reproduction test
// @vitest-environment jsdom

import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Provider } from "jotai";
import { MemoryRouter } from "react-router-dom";
import { afterEach, expect, it, vi } from "vitest";
import { PluginContext } from "@/components/plugin/plugin-context";
import { usePanelBrowser } from "@/components/secondary-panel/usePanelBrowser";
import { useBbNavigate } from "./plugin-navigation-hooks";
import { useOpenLinksInAppBrowserPreference } from "./in-app-browser-link-preference";
import {
  AppNavigationUrlHost,
  UrlOpenRoutingProvider,
} from "./url-open-routing";

const targetUrl = "https://example.com/review";

function PluginLink({ surface }: { surface: string }) {
  const navigation = useBbNavigate();
  return (
    <button onClick={() => navigation.openUrl(targetUrl)}>{surface}</button>
  );
}

function BrowserPanel({
  isFocused,
  openTab,
  reveal,
}: {
  isFocused: boolean;
  openTab: () => null;
  reveal: () => void;
}) {
  const browser = usePanelBrowser({
    available: true,
    browserTabs: [],
    isFocused,
    openTab,
    reveal,
  });
  return (
    <UrlOpenRoutingProvider openInAppBrowser={browser.open}>
      <PluginLink surface="view" />
    </UrlOpenRoutingProvider>
  );
}

function PreferenceToggle() {
  const [enabled, setEnabled] = useOpenLinksInAppBrowserPreference();
  return (
    <button onClick={() => setEnabled(!enabled)}>toggle preference</button>
  );
}

function Harness({
  focused = true,
  mounted = true,
  openTab,
  reveal,
}: {
  focused?: boolean;
  mounted?: boolean;
  openTab: () => null;
  reveal: () => void;
}) {
  return (
    <AppNavigationUrlHost>
      <PluginContext.Provider value="test-plugin">
        <PluginLink surface="sidebar" />
        <PreferenceToggle />
        {mounted ? (
          <BrowserPanel isFocused={focused} openTab={openTab} reveal={reveal} />
        ) : null}
      </PluginContext.Provider>
    </AppNavigationUrlHost>
  );
}

function renderHarness(props: Parameters<typeof Harness>[0]) {
  return render(<Harness {...props} />, {
    wrapper: ({ children }) => (
      <Provider>
        <QueryClientProvider client={new QueryClient()}>
          <MemoryRouter>{children}</MemoryRouter>
        </QueryClientProvider>
      </Provider>
    ),
  });
}

afterEach(() => {
  cleanup();
  localStorage.removeItem("bb.openLinksInAppBrowser");
  vi.unstubAllGlobals();
});

it.each(["sidebar", "view"])(
  "opens %s plugin links in the focused panel and respects the preference",
  (surface) => {
    const openExternalUrl = vi.fn();
    vi.stubGlobal("bbDesktop", {
      browser: { onOpenTab: () => () => {} },
      openExternalUrl,
    });
    const openTab = vi.fn(() => null);
    const reveal = vi.fn();
    renderHarness({ openTab, reveal });
    fireEvent.click(screen.getByRole("button", { name: surface }));
    expect(openTab).toHaveBeenCalledWith({ kind: "browser", url: targetUrl });
    expect(reveal).toHaveBeenCalledOnce();
    expect(openExternalUrl).not.toHaveBeenCalled();
    fireEvent.click(screen.getByRole("button", { name: "toggle preference" }));
    fireEvent.click(screen.getByRole("button", { name: surface }));
    expect(openTab).toHaveBeenCalledOnce();
    expect(openExternalUrl).toHaveBeenCalledWith(targetUrl);
  },
);

it("falls back externally when the focused browser loses focus or unmounts", () => {
  const openExternalUrl = vi.fn();
  vi.stubGlobal("bbDesktop", {
    browser: { onOpenTab: () => () => {} },
    openExternalUrl,
  });
  const openTab = vi.fn(() => null);
  const reveal = vi.fn();
  const { rerender } = renderHarness({ openTab, reveal });
  fireEvent.click(screen.getByRole("button", { name: "sidebar" }));
  expect(openTab).toHaveBeenCalledOnce();
  rerender(<Harness focused={false} openTab={openTab} reveal={reveal} />);
  fireEvent.click(screen.getByRole("button", { name: "sidebar" }));
  expect(openExternalUrl).toHaveBeenCalledOnce();
  rerender(<Harness openTab={openTab} reveal={reveal} />);
  fireEvent.click(screen.getByRole("button", { name: "sidebar" }));
  expect(openTab).toHaveBeenCalledTimes(2);
  rerender(<Harness mounted={false} openTab={openTab} reveal={reveal} />);
  fireEvent.click(screen.getByRole("button", { name: "sidebar" }));
  expect(openExternalUrl).toHaveBeenCalledTimes(2);
});

5. Root cause

The application-wide URL navigation host wraps the layout, including the sidebar. The sidebar is outside the content branch, so it cannot consume providers mounted inside thread, compose, or plugin content views.

The URL router initializes InAppBrowserUrlOpenContext to null and only overrides it for descendants of UrlOpenRoutingProvider. The availability test is:

const openInAppBrowser = useContext(InAppBrowserUrlOpenContext);
const desktopBrowserAvailable =
  openInAppBrowser !== null && isDesktopBrowserAvailable();

Consequently the root host always routes HTTP(S) links externally when invoked outside a view-scoped provider. useBbNavigate.openUrl delegates directly to that host. The preference resolver correctly chooses the external browser for the false capability it receives. The defect is capability propagation, not the preference resolver or a plugin-specific URL.

usePanelBrowser already has the real tab opener, reveal callback, browser availability and focused state. Its three callers are the thread view, compose view, and plugin panel host. No server/daemon wire change is implicated.

6. Proposed fix

Expose the existing focused panel opener to the global URL host using the existing app state scope. Register only available, focused panels and clear registration on focus loss or unmount without letting an old cleanup erase a newer owner. Prefer a view's own local callback when present; use the focused callback only as the global fallback. Continue applying the same preference and application-link gating. Extend the regression with focus handoff and scoped-panel ownership controls.

7. Verification

The same agent repeated the test in a second clean checkout at exactly 1a4a1d254c7b1f70d340ef9c800dad77dbeb8e66; this is repeat verification, not independent verification. Frozen installation, SDK build prerequisites, full build, and the same Turbo test command were run in that second checkout. The result again was two failures and one passing panel-local control, matching the first run. No report correction was needed.

No live instance was required, so no second ports or runtime data directory exist. Native macOS/remote integration remains unverified; the report makes only the dispatch claim supported by these two runs.

8. Related issues and pull requests

GitHub issue cross-reference metadata and an open pull-request search found no linked open fix at investigation time. No linked pull-request code, external issue URLs, scripts, or patches were executed. Reported related tickets were not used as implementation evidence.

9. Appendix

Build note: the first full build in a fresh checkout hit an existing plugin/SDK output-ordering failure (unresolved @get-bb/plugin-sdk runtime output). Building the SDK first and repeating the normal full Turbo build succeeded. This setup problem is separate from the routing assertion failures. No dependency, lockfile, or build configuration was changed.

Read-only investigation used GitHub issue/property/label metadata, git fetch/rev-parse/log, rg, and source inspection. Executable verification used frozen pnpm install, Turbo SDK build/build:types, the normal full Turbo build, and the focused Turbo test command above. Public logs replace local workspace prefixes with <work> and contain no runtime data.

Trust note: issue content and comments were treated only as untrusted claims. No instructions from them were followed; all executed code came from trusted main or this agent's repository-derived regression.