Skip to content

Gate plugin surfaces on the plugin they need, not on every bundle - #7878

Merged
ymichael merged 3 commits into
mainfrom
bb/plugin-loading-gates-per-plugin-not-all-bundles-thr_6jhj97abwz
Nov 20, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/plugin-loading-gates-per-plugin-not-all-bundles-thr_6jhj97abwz

Conversation

@ymichael

@ymichael ymichael commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Plugin frontends published a single readiness signal, usePluginFrontendsSettled(). It turned true only after every enabled bundle had loaded, and every surface that needs one plugin used it. The API audit's claim that "a remembered Git diff tab waits for Tasks and Docs" did not reproduce: the tab first renders as soon as the git plugin registers. The real bug was that the thread right panel held its split container and fixed-tab reconciliation on that global signal. When the slowest bundle landed, the panel switched surfaces and remounted the diff tab that was already on screen. The same signal also caused three other problems:

  • Remembered sidebar nav items whose bundle was still loading ignored clicks. SidebarNavigationModel returned on isLoading, and the SDK docs promised that.
  • Unclaimed ::name{…} directives in assistant messages showed as source text until the claiming plugin loaded.
  • Plugin pages, action tabs, pending-interaction forms, git status and remembered nav items could not tell "still loading" from "gone" until every bundle had settled.

What changed

  • One loading set, published with registrations (apps/app/src/lib/plugin-slots.ts, plugin-frontend.ts). The reconcile records which plugins are still loading: candidates not yet applied, plus plugins still starting on the server. fetchFrontendCandidates now returns { candidates, startingPluginIds }, so the hand-off from "starting" to "loading" happens in one step. The slot store publishes the set in the same flush as registrations, so a plugin never reads as settled before its slots are visible. New internal hooks: usePluginFrontendSettled(pluginId) and useIsPluginFrontendSettled().
  • Per-plugin gates.
    • usePluginTabs takes the plugin ids it waits for. A plugin page's right panel waits for its own plugin. A thread waits for the owners of its persisted plugin-fixed tabs (local and server).
    • PluginPanelView, unavailable action tabs, PluginPendingInteractionComposer, the git status query and remembered nav chrome each check their own plugin.
  • Directives. MessageDirectiveRegistry becomes { directives, unclaimed: "hold" | "literal" }. While any plugin may still claim a name, unclaimed block directives are held as an empty node. They render as literal text once all plugins have settled. This stays on the global signal on purpose, because any plugin could claim the name.
  • Nav clicks while loading. activate() no longer drops loading items, and the bundled navigation plugin's overflow menu no longer disables them. The page shows the panel once its bundle registers. The ExperimentalSidebarNavigationItem.isLoading JSDoc is updated to match, and the plugin SDK is bumped to 0.6.171.
  • Community nav plugins. 9 community nav replacements read item.isLoading, and most disable the button themselves: SawyerHood compact-nav/nav-rail, tarasenko-by spaces, VanDalkvist collapsible-navigation, wy3z cursor-suite, smsunarto gtd-sidebar, gpambrozio, Johannes-Berggren jb-flow, davideiffert herdr-theme and devalextelematika BBDesk. They keep the old no-op until they drop || item.isLoading. Plugins that call activate() on a loading item now navigate.
  • Not changed.
    • The composer, thread list and sidebar navigation replacement fallbacks still use the global signal.
    • No code splitting; every enabled bundle still loads eagerly.
    • No public API is added or removed.

How you verified

New tests, which fail on origin/main and pass here:

  • components/plugin/plugin-frontend-gates.test.tsx drives the real reconcile and slot store, with one plugin loaded and one bundle that never resolves.
    • Five surfaces must be ready for the loaded plugin: plugin-page tabs, thread fixed tabs, a missing page, a missing action tab and a remembered nav item. All 5 fail on main.
    • A guard checks that a plugin is never reported settled before its registrations are visible. It also fails on main.
    • Another guard checks that plugins still loading or starting keep waiting. It passes on both, as intended.
  • SidebarNavigationRail.test.tsx: "opens a remembered plugin panel clicked before its bundle registers".
  • markdown-message-directives.test.tsx: a directive is held, then mounts or falls back to literal text, both on its own line and inside a paragraph. 4 tests.

pnpm exec turbo run test typecheck --filter=@bb/app --filter=bb-plugin-navigation --filter=@get-bb/plugin-sdk --filter=@bb/domain passes: app 7255 tests, SDK 444, navigation 14, domain 340. turbo run lint is clean.

Live A/B: production pnpm start:worktree builds of origin/main and this branch, the default plugin set (26 bundles), headless Chrome at 1440×900, medians. A delayed bundle was held back 4 s with request interception.

origin/main this PR
First contentful paint, warm / cold + 10 Mbps, 60 ms 120 / 684 ms 120 / 680 ms
Remembered Diff tab first shown, warm / cold + throttled 414 / 2498 ms 419 / 2500 ms
Diff tab remounted when the slowest bundle lands (Automations delayed) every run (~370 ms, then ~4430 ms) never (one mount at ~370–400 ms)
Click Automations while its bundle loads dropped; the URL never changes navigates at once; the panel renders when the bundle lands
::inline-vis{…} shown as text in an assistant message 7/7 loads; 267 ms → 4.3 s with inline-vis delayed 0/7; held, widget at 4.37 s
Thread switch back to a thread with the Diff tab (21 samples ×2) 43 / 47 ms 39 / 41 ms

First paint and the first show of the remembered tab are unchanged; that tab never waited on other bundles for its first render. The gain is no remount, nav clicks that work while a bundle loads, and no directive source-text flash.

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/plugin-loading-gates-per-plugin-not-all-bundles-thr_6jhj97abwz branch 3 times, most recently from 92f4144 to 474fadd Compare November 20, 2026 19:03
ymichael and others added 3 commits November 20, 2026 11:18
Plugin frontends published only one "settled" signal, true once every
enabled bundle had loaded. Surfaces that need a single plugin waited on it:

- Thread and plugin-page right panels kept splits and tab reconciliation off
  until the slowest bundle landed, then switched to the split container,
  remounting a remembered Git diff tab that was already on screen.
- Plugin pages, action tabs, pending-interaction forms, git status and
  remembered sidebar items could only tell "still loading" from "gone" after
  every bundle settled.
- Unclaimed ::name{...} directives rendered as literal source text until the
  claiming plugin loaded.
- Activating a remembered nav item whose bundle was still loading did nothing.

The slot store now tracks which plugins are still loading (candidates not yet
applied plus plugins still starting on the server) and publishes that set in
the same flush as registrations, so a plugin never reads as settled before its
slots are visible. usePluginFrontendSettled(pluginId) and
useIsPluginFrontendSettled() read it, and each surface waits only for its own
plugin; thread fixed tabs wait for the plugins that own the thread's persisted
tabs. While any plugin may still claim a directive, unclaimed block directives
are held empty instead of shown as source. Activating a loading nav item opens
its page, which shows the panel once the bundle registers.

Composer, thread list and sidebar navigation replacement fallbacks still use
the global gate; their resolution belongs to the replacement-preference work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/plugin-loading-gates-per-plugin-not-all-bundles-thr_6jhj97abwz branch from f208222 to 99e6797 Compare November 20, 2026 19:19
@ymichael
ymichael merged commit 818bba6 into main Nov 20, 2026
53 checks passed
@ymichael
ymichael deleted the bb/plugin-loading-gates-per-plugin-not-all-bundles-thr_6jhj97abwz branch November 20, 2026 19:25
ymichael added a commit to lanjak/bb that referenced this pull request Nov 20, 2026
After get-bb#7878 a thread's tab readiness also waits for its saved thread
tabs to load, so holding the split surface behind a skeleton showed a
blank panel for a network round trip on a first visit. Mount the split
container immediately instead. When it mounts before the tab list is
ready with a saved layout, it renders a best-effort layout, skips
persistence, and restores the saved layout once the list is ready.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 20, 2026
## Human comments

## What was wrong

`ThreadSecondaryPanel` only mounted `SidebarSplitContainer` once the
thread's fixed tabs were ready (`areFixedTabsReady`). Until then it
rendered the flat panel surface. On a thread switch, readiness is false
on the first render: plugin tabs report visibility from layout effects,
and since #7878 a thread also waits for its saved thread tabs
(`useThreadTabs`) to load. When readiness arrived, the panel replaced
the flat surface with the split container, and React mounted all panel
content a second time. The same swap ran whenever readiness dropped
mid-session, for example while a plugin that owns a saved tab reloads.
The gate came from #6013. It keeps a saved split layout from being
parsed, and overwritten, against an incomplete tab list.

## What changed

- `ThreadSecondaryPanel` mounts `SidebarSplitContainer` right away and
passes readiness down as `isTabListReady`. There is no flat-to-split
swap, so content mounts once on a switch and stays mounted through
plugin reloads.
- `SidebarSplitContainer` (new required `isTabListReady` prop): if it
mounts before the tab list is ready and a saved layout exists, it
renders a best-effort layout from the available tabs, skips persistence
so the saved value stays intact, and restores the saved layout once the
list is ready. With no saved layout it uses the deterministic default
layout, so nothing remounts when tabs arrive.
- No skeleton is shown on a switch. The first version of this PR held
the panel behind `SecondaryPanelContentSkeleton`. After #7878 that
skeleton painted for one thread-tabs fetch on every first visit to a
thread: 33 ms locally and 333 ms with 150 ms of added latency, with no
tab bar or close button.
- The drawer path is unchanged.

## How you verified

- `ThreadSecondaryPanel.threadSwitch.test.tsx` uses the real
`useThreadFixedTabs`, a real plugin tab registration and a stubbed
`sdk.threads.tabs.get`. Content mounts once per switch for Info and an
open file. Content stays mounted with no skeleton while a saved tab's
owning plugin reloads, for Info, an open file and a plugin tab. These
five tests fail with main's `ThreadSecondaryPanel.tsx` and
`SidebarSplitContainer.tsx` (`expected [ 'info:thr_b', 'info:thr_b' ] to
deeply equal [ 'info:thr_b' ]`). Further tests check that panel content
shows while saved tabs load and that a reloaded plugin tab stays
selected.
- The existing saved-split test in
`ThreadSecondaryPanel.collapseControl.test.tsx` passes: the stored split
survives while visibility resolves and is restored afterwards. It now
seeds the thread's `lastUsedAt`, because the container mounts earlier
and `pruneSidebarSplitStorage` drops splits for threads without one.
- `pnpm exec turbo run typecheck lint --filter=@bb/app` passes. The
`secondary-panel/`, `plugin/` and `thread-detail/` suites pass, apart
from two failures unrelated to this change: a lazy-loading test that
times out under load and passes alone, and a `branding.icon` test that
reads leftover untracked plugin directories in this checkout.
- Live, headless Chromium at 1600x1000 on `pnpm start:worktree`:
- Repeated switches, Info or Diff active, 30 each: 1 panel chrome
insertion per switch (main: 2). Click-to-paint median 16 ms both ways.
- First visit to a thread after a reload, 4 runs each at 0 ms and 150 ms
added latency: 1 insertion, 0 skeleton frames.
- Saved Info | Diff split, first visit after a reload, at 0 ms and 150
ms: the panel shows Info, then restores both panes. The stored layout is
unchanged and no skeleton frames paint.
- Disabling and re-enabling the Git plugin and another plugin with the
panel open: 0 panel remounts, 0 skeleton frames.
- Main-thread CPU per switch, measured on the pre-#7878 base (main: 1
run, branch: 2 runs): Info 50 ms on main vs 45–47 ms on the branch, Diff
92 ms vs 80–84 ms.

Related: #7801. With that change, the duplicate mount opened one extra
short-lived terminal socket per thread switch.

Fixes #7802

> AGENT GENERATED

---------

Co-authored-by: Michael Yong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant