Repository navigation
Defer plugin frontend boot past first route paint with bounded, ordered loads (A3, B23) - #1896
Merged
SawyerHood merged 4 commits intoAug 19, 2026
Conversation
This was referenced Aug 19, 2026
Merged
SawyerHood
force-pushed
the
bb/mobile-perf/plugin-boot-defer
branch
2 times, most recently
from
August 19, 2026 07:50
f2cf113 to
b76b34b
Compare
SawyerHood
marked this pull request as ready for review
August 19, 2026 08:04
SawyerHood
force-pushed
the
bb/mobile-perf/plugin-boot-defer
branch
from
August 19, 2026 15:59
b76b34b to
19e75e1
Compare
…ed loads Every running plugin's app bundle (about 3 MB unminified JS plus about 780 KB CSS across the default set) started importing the moment /system/config resolved, all at once via Promise.all, each injecting its own stylesheet on arrival. On a phone that parse/eval and the dozen style invalidations landed in the same window in which the route chunk was still downloading, so first route content painted late. - Boot now waits for system config AND the first route content to commit (a RouteContentPaintSignal sibling inside the route Suspense boundary) plus an idle slot (requestIdleCallback, or two animation frames on WebKit), bounded by a 1.5 s timeout so plugins never wait on a route that does not resolve. A /plugins/:pluginId panel route still boots as soon as config resolves: the plugin is the page there. - reconcilePluginFrontends imports at most three bundles at a time. The plugin owning the current panel route goes first, then ascending bundle size, so several light plugins register before one heavy one. The server now reports jsBytes for each app bundle (server-contract pluginAppStateSchema, GET /api/v1/plugins) to drive that order. - Stylesheet insertions coalesce into one animation frame; removals stay synchronous and cancel a pending insertion (teardown must not leave a sheet behind). The pagehide teardown wiring in plugin-frontend.ts is untouched. Co-Authored-By: Claude <[email protected]>
… over realtime
The workflows composer banner called workflowActiveRuns every second on
every open thread for as long as it was mounted, whether or not the
thread had a run and whether or not the tab was visible. On a phone that
kept the radio and main thread busy on idle threads.
- The service publishes a `workflow-runs` realtime signal `{ threadId }`
for the origin thread when a run is created, claimed, settled, or
cancelled. The banner subscribes and refreshes on a matching signal,
so an idle thread needs no standing poll to show a new run.
- Both the banner and the workflow-preview directive poll once per
second only while a run is active (or the last fetch errored) and
document.visibilityState is not hidden. Coming back to the tab, or the
realtime connection returning to `connected`, triggers one catch-up
refresh before the cadence resumes.
Co-Authored-By: Claude <[email protected]>
…s field packages/templates embeds @get-bb/plugin-sdk/bundled-types as strings and its typecheck/test scripts assert the embed is current. The previous commit added jsBytes to the plugin app bundle schema, which the bundled declarations reflect. Co-Authored-By: Claude <[email protected]>
…export lib.dom already declares requestIdleCallback/cancelIdleCallback, so the feature check works on window directly (AGENTS.md: no internal casts). isRouteContentPainted had no callers. Co-Authored-By: Claude <[email protected]>
SawyerHood
force-pushed
the
bb/mobile-perf/plugin-boot-defer
branch
from
August 19, 2026 16:13
19e75e1 to
0be12a3
Compare
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…pp bundles (A4, H7) (#1895) ## What was wrong Plugin frontend bundles were built without minification, and every plugin's `app.css` carried the Tailwind utilities of all of `@bb/shared-ui`: `bb.pluginTailwindContent: ["src/**/*"]` fed the whole package glob to the scanner whether or not the plugin imported those components (~110 KB / ~1200 rules per sheet, plus a `:root` block that re-declared the host's semantic token bridge). On phones the raw bytes drive parse time, each stylesheet insertion is a document-wide restyle, and ~17k scoped rules stay resident. (A4) Four first-party provider plugins (claude-code, codex, pi, acp) shipped an app bundle whose only job was to register, through `experimental_providerIcon`, an SVG byte-identical to the one the host already vendors in `BUILT_IN_BRAND_ICONS`: four JS fetches, four CSS fetches, four stylesheet inserts and four icon remounts per page load for no visible change. (H7) ## What changed - `buildPluginApp` builds with `minify: true`, `legalComments: "none"`, and takes `{ minify }`; `bb plugin dev` passes `{ minify: false }` so stack traces and CSS stay readable while iterating. Server installs and `bb plugin build` minify. - The Tailwind output plus authored CSS run through Tailwind's own optimizer (`optimize` from `@tailwindcss/node`, the lightningcss pass the host's Vite build uses); minified in production, pretty in dev, same browser-target lowering in both. - `bb.pluginTailwindContent` globs now only select which dependency files may be scanned; the scan reads their intersection with esbuild's `metafile.inputs`, so a plugin pays only for the shared components it bundles. Scan bases are realpath'd because esbuild reports real paths for workspace links. - The generated plugin theme marks the host's `@theme inline` bridge as `inline reference`: inline tokens are substituted into utilities at compile time, so the `:root { --color-*: var(--*) }` block was never read by plugin rules. Non-inline tokens still emit. - Removed `app.tsx` / `bb.app` / react devDeps from the four provider plugins; updated the provider-icon comment, `docs/api_to_audit.md`, and the plugin-authoring skill example that pointed at the deleted file. Built-in bundle bytes (raw / gzip), before -> after: | plugin | app.js | app.css | | --- | --- | --- | | tasks | 2,383,490 / 503,399 -> 1,257,491 / 360,279 | 127,234 / 15,866 -> 51,898 / 8,763 | | docs | 1,641,918 / 374,940 -> 839,167 / 262,909 | 112,434 / 14,127 -> 30,250 / 5,502 | | automations | 1,064,406 / 185,248 -> 587,528 / 141,850 | 112,712 / 14,112 -> 51,952 / 8,449 | | secrets | 644,324 / 100,199 -> 352,915 / 76,467 | 110,067 / 13,891 -> 17,288 / 3,321 | | provider-* (x4) | ~2-3.6 KB each -> none | ~3-4.3 KB each -> none | ## How you verified - New tests in `packages/plugin-build/src/build-plugin-app.test.ts`: minified vs readable artifacts (identifier mangling, license comment dropped, CSS minified/pretty for both utilities and authored CSS); dependency scanning through a symlinked package with a negated pattern (bundled file scanned, glob-only file not, negated file not, plugin's own dir still scanned whole, `:root` has the default token and not the bridge). Both fail before the change. - Updated dependent assertions for minified CSS in `apps/cli` plugin-build test, `apps/server` plugin-app-bundle test, and `packages/plugin-registry` vendor test. - `turbo run typecheck` for @bb/plugin-build, @bb/cli, @bb/server, @bb/app, @bb/plugin-registry and the four provider plugins: pass. `turbo run lint --filter=@bb/app`: pass. - `turbo run test`: @bb/plugin-build full suite (22 passed, 1 skipped); @bb/cli plugin-build, docs/github official bundle, packaged-plugin-build, plugin-dev-loop (21 passed); @bb/server `test/services/plugins` (34 files, 380 passed); @bb/plugin-registry vendor-all-items; @bb/app provider-icon test. - Rebuilt all builtins with `apps/server/scripts/copy-builtin-plugins.ts` before and after for the byte table above. Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 16 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/pierre-pool-and-route-closure` (#1894). - Next layer: `bb/mobile-perf/plugin-boot-defer` (#1896). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s). - Reviewer notes / follow-ups: Minified production plugin bundles ship without source maps (implementer-acknowledged; dev loop is readable). Not a blocker. | Authored plugin CSS now passes through lightningcss (errorRecovery on, warnings printed); invalid authored CSS is dropped at build time rather than by the browser. Behavioural but | Four touched files (bb-plugin-authoring SKILL.md, generate-plugin-theme.mjs, vendor-all-items.test.ts, provider-pi/tsconfig.json) are not prettier-clean, but they were already not - Wire/contract: None. No server<->daemon wire, RPC, or session payload changed; HOST_DAEMON_PROTOCOL_VERSION untouched. Artifact format (dist/app.js, app.css, app.meta.json, artifactFormatVersion 1) unchanged; only content minification. Public API: `buildPluginApp(rootDir, bbVersion, toolchain, options?: PluginAppBuildOptions)` gained an optional 4th arg (exported type PluginAppBuildOptions from @bb/plugin-build) > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[email protected]>
SawyerHood
added a commit
that referenced
this pull request
Aug 19, 2026
…lots (A5, partial) (#1897) ## What was wrong Every plugin app bundle carried its own copy of libraries the host already ships (audit A5). zod (~516 KB raw / ~75 KB gzip) was bundled by four builtins, tailwind-merge + clsx by thirteen, class-variance-authority by most, and the shared-ui `Icon` with its ~110 KB hugeicons map by twelve. Phones parsed and evaluated all of it on every page load. `RUNTIME_SLOT_BY_SPECIFIER` in packages/plugin-build only shimmed react, the SDK, pierre, the portal radix families, sonner and vaul. ## What changed - `bb plugin build` routes `zod`, `clsx`, `tailwind-merge`, `class-variance-authority` and `@bb/shared-ui/icon` to new `globalThis.__bbPluginRuntime` slots (`zod`, `clsx`, `tailwindMerge`, `classVarianceAuthority`, `sharedUiIcon`). shared-ui's own components import the icon module as `./icon`; the esbuild plugin routes that import to the same slot when the importer lives in shared-ui's source tree. A plugin's vendored `icon.tsx` still bundles. - Shims forward a real default export (`mod.default` when the host namespace has one), so `import clsx from "clsx"` receives the callable, not the namespace. - Host (`apps/app/src/lib/plugin-frontend.ts`) installs the five slots. Export manifest regenerated (`@bb/shared-ui/icon` exports come from esbuild metadata like the SDK facade). - `PLUGIN_SDK_VERSION` 0.4.8 -> 0.4.9. Old bundles keep working (they carry their own copies); new bundles need the new host slots, so path/builtin plugins rebuild on the sdkVersion-differs trigger and scaffolds pin the floor. - Scaffold generator moves clsx/tailwind-merge/cva to type-only deps (zod stays a dependency: server.ts bundles it). Guide and bb-plugin-authoring skill updated. CLI scaffold-dependency test now applies the shim exemption only to app-side files. - `apps/app/bundle-budget.json` raised: exposing the whole zod namespace stops the boot chunk from tree-shaking zod exports the app never calls: boot payload 1655.7 KB / 449.1 KB brotli -> 1848.4 KB / 481.7 KB (+193 KB raw, +33 KB brotli). The other four slots add under 2 KB. Removing `zod` from RUNTIME_SLOT_BY_SPECIFIER reverts both sides of the trade. Builtin app.js after rebuild: 8.87 MB -> 4.01 MB raw (-55%), 1.76 MB -> 0.93 MB gzip (-47%). Per plugin (raw): ask-user-question 784 KB -> 38 KB, automations 1063 -> 315, connect 376 -> 145, custom-instructions 99 -> 9, docs 1640 -> 1419, github 416 -> 185, inline-vis 239 -> 9, keep-awake 308 -> 79, memory 122 -> 30, provider-retry 249 -> 18, secrets 644 -> 37, side-chat 241 -> 11, tasks 2380 -> 1638, workflows 300 -> 69. ## How you verified - New tests in `packages/plugin-build/src/build-plugin-app.test.ts`: every non-SDK slot has a manifest entry; a bundle importing the five libraries compiles with no node_modules and, executed against a fake runtime, yields the callable clsx default, `z`, `twMerge`, `cva`, `Icon`; shared-ui's relative `./icon` import is shimmed while a plugin's own `components/ui/icon.tsx` still bundles; `isSharedUiIconRelativeImport` unit cases. `apps/app/src/lib/plugin-frontend.test.ts` asserts the new slots and their identity with the host modules. - `pnpm exec turbo run typecheck lint` for @bb/plugin-build, @bb/templates, @get-bb/plugin-sdk, @bb/domain, @bb/app, @bb/cli, @bb/server: green. `pnpm exec turbo run test` for @bb/plugin-build (24 passed), @bb/templates (44), @bb/plugin-registry (1), plugin-sdk version test, CLI plugin-build/plugin-new/packaged-plugin-build/plugin-guide-docs/plugin-dev-loop/docs- and github-official-plugin-bundle/plugin-scaffold-dependencies tests, server plugin-app-bundle + plugin-sdk tests, app plugin-frontend test: all green. - `pnpm exec turbo run build --filter=@bb/app` + `node scripts/check-bundle-budget.mjs`: passes with the ratchet. - Rebuilt all 18 plugin app bundles through buildPluginApp (sizes above). Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue). ## Stack context Layer 18 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins first, big rocks last). - Prerequisite (layer below): `bb/mobile-perf/plugin-boot-defer` (#1896). - Next layer: `bb/mobile-perf/rerender-amplifiers` (#1898). - Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s). - Partial: A5 (bundle splitting): not implemented (outdir + esbuild splitting + served chunks). Slots shipped; splitting plan described in the report. - Reviewer notes / follow-ups: A5 'splitting' (outdir + splitting, lazy definePluginApp components) is not implemented; the branch only covers the host-slot half of A5, as the implementer reported. | Design trade-off to be aware of, not a defect: exposing the full zod namespace on __bbPluginRuntime stops the host boot chunk from tree-shaking zod (+193 KB raw / +33 KB br on boot | Compatibility note (pre-existing pattern, same as the earlier @pierre/diffs slot): a plugin app built with the new bb plugin build throws 'Cannot load "zod"' if loaded by an older - Wire/contract: No server<->host-daemon wire change; HOST_DAEMON_PROTOCOL_VERSION untouched. Plugin runtime contract: five new slots on globalThis.__bbPluginRuntime (zod, clsx, tailwindMerge, classVarianceAuthority, sharedUiIcon); RUNTIME_SLOT_BY_SPECIFIER gains zod, clsx, tailwind-merge, class-variance-authority, @bb/shared-ui/icon; runtime shims now export `("default" in mod ? mod.default : mod)` as default. PL > AGENT GENERATED: by Claude Code (claude-mangosteen-eap) --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
/system/configresolved, all at once viaPromise.all, each injecting its own<link rel=stylesheet>on arrival. On a phone this parse/eval and the dozen style invalidations landed in the same window in which the route chunk was still downloading, so first route content painted late. (Audit finding A3.)workflowActiveRunsonce per second on every open thread for as long as it was mounted, whether the thread had a run and whether the tab was visible. (Audit finding B23.)What changed
usePluginFrontendBootwaits for system config, then for the first route content to commit (RouteContentPaintSignal, a sibling of the lazy routes inside their Suspense boundary) plus an idle slot (requestIdleCallback, or two animation frames on WebKit), bounded by a 1.5 s timeout. A/plugins/:pluginId/...route boots as soon as config resolves because the plugin is the page there.reconcilePluginFrontendsimports at most three bundles at a time. The plugin that owns the current panel route goes first, then ascending bundle size. The server now reportsjsBytesper app bundle (pluginAppStateSchema,GET /api/v1/plugins).createBatchedPluginCssApplier); removals stay synchronous and cancel a pending insertion. The pagehide teardown wiring is untouched.workflow-runsrealtime signal for the origin thread on run create, claim, settle, and cancel. The banner subscribes and refreshes on a matching signal. Banner and preview directive poll once per second only while a run is active (or the last fetch errored) anddocument.visibilityStateis not hidden, with one catch-up refresh when the tab or the realtime connection comes back.How you verified
apps/app/src/lib/plugin-frontend-boot-schedule.test.ts(paint+idle vs timeout vs cancel),apps/app/src/hooks/usePluginFrontendBoot.test.tsx(no boot on config alone; boot after paint+idle; boot at 1.5 s; immediate boot on plugin panel route),apps/app/src/lib/plugin-frontend-load-order.test.ts(ordering, max-3 concurrency and lane hand-off, failure isolation, CSS batching/removal),plugins/workflows/src/app.test.tsx(idle thread never polls, realtime signal triggers one refresh and polling starts/stops with active runs; hidden document pauses polling and refreshes once on return),plugins/workflows/src/service-policy.test.ts(signal published on start/claim/cancel, not on a no-op stop),apps/server/test/services/plugins/plugin-app-bundle.test.ts(jsBytes equals dist/app.js size).pnpm exec turbo run typecheckfor @bb/app, @bb/server, @bb/server-contract, @bb/templates, @bb/cli, @bb/sdk, bb-plugin-workflows: pass.pnpm exec turbo run lint --filter=@bb/app: 0 errors, no warnings in touched files.pnpm exec turbo run build --filter=@bb/app+node scripts/check-bundle-budget.mjs: bundle budget OK (449.2 KB br boot). Targeted vitest runs listed above: all pass.Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue).
Stack context
Layer 17 of 22 in the
bb/mobile-perf/*stack (bottom → top: quick wins first, big rocks last).bb/mobile-perf/plugin-build-minify(Minify plugin app bundles, optimize their CSS, drop provider plugin app bundles (A4, H7) #1895).bb/mobile-perf/plugin-host-slots(Shim clsx, tailwind-merge, cva and the shared icon onto plugin host slots (A5, partial) #1897).jsBytes: numberfield (packages/server-contract pluginAppStateSchema, apps/server app-bundle.ts, apps/app isFrontendBundle guard). This is server<->browser only; nothing on the server<->host-daemon wire changed, so HOST_DAEMON_PROTOCOL_VERSION was not bumped. Regenerated tracked artifacts: packages/plugin-sdk/bund