Skip to content

Measure page journeys, add defineSplit tiers, and cut boot and thread-page JavaScript - #4955

Merged
ymichael merged 12 commits into
mainfrom
bb/bundle-headroom
Oct 5, 2026
Merged

ymichael merged 12 commits into
mainfrom
bb/bundle-headroom

Conversation

@ymichael

@ymichael ymichael commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The workspace route's bundle budget sat within 0.1 KB of its limit, so ordinary feature work kept turning main red (#4933 temporarily raised it). The budget measured the SplitWorkspaceRoute closure, which moved whenever code shifted between the route chunk and a page's own lazy chunk, not the JavaScript a page actually waits for. Code-split preloading was opt-in per call site: startup/idle policies did nothing unless a mounted owner also called useSplitPreload. And the workspace route's import only started after boot downloaded and ran, a full round trip behind it.

What changed

  • Budgets measure page journeys. ThreadPage (route + ThreadDetailView) and NewThreadPage (route + RootComposeView) replace the route closure in bundle-budget.json; split-boundary guards check both journeys. Journey limits are 25% above measured size (20% headroom); boot limits are unchanged.
  • defineSplit tiers. tier: "preload" | "intent" replaces four policies. Preload splits queue themselves and drain at idle once no critical load (route import, current page split, any rendered split) is pending; intent splits load on render or trigger intent. Mount gating (mountWhen, keepMounted, unmounted) replaces three hand-written gates. Remaining React.lazy feature boundaries below the router move to defineSplit; router pages in App.tsx stay React.lazy because they suspend into the boundary that marks route content painted.
  • Route content painted now fires after critical loads settle rather than when the route skeleton renders, so preload-tier work and plugin frontend boot no longer compete with the page's own code.
  • Smaller boot: "sideEffects": false on client-core, thread-view, core-ui; sonner loads after first paint (appToast queues until the Toaster mounts; plugin frontends wait for it); the server-move overlay view loads after paint.
  • Smaller thread page: RootComposeView loads on demand; the legacy project redirect moves to its own module.
  • Microphone preferences load on demand behind PickerLoadingRows.
  • New-thread composer banner stack hides unless a child has content. A bare plugin banner that renders nothing (scheduled-send) still mounts an empty display: contents root, which defeated empty:hidden and added an 8px margin when plugins booted after first paint, moving the composer down. Base shows the same shift on slower loads.
  • index.html modulepreloads the workspace route and its static dependencies so they download alongside boot.
  • Docs: docs/ui-code-splitting.md, docs/ui-split-loading-audit.md. No wire, CLI, SDK, or data changes.
Minified JS main this PR Limit
Boot 1492 KB / 371 KB br 1359 KB / 340 KB br 1602 KB (15% headroom)
ThreadPage 1880 KB / 545 KB br 1807 KB / 520 KB br 2259 KB (20%)
NewThreadPage 1059 KB / 309 KB br 1091 KB / 321 KB br 1364 KB (20%)

How you verified

  • pnpm exec turbo run build typecheck lint test --filter='...[origin/main]': 230/232 tasks passed; the failure was PluginSettings.test.tsx > autosaves the latest text value on blur under parallel load, which passes 3/3 alone and touches no changed code.
  • New tests: split tiers and preload queue, critical-load gating (fails without the gate), mount gating, page-journey stats, toast queueing before the Toaster mounts, route modulepreload build output.
  • Product-path verification against isolated running BB servers (head and base control) with a connected daemon and a real Claude Code thread is recorded in the reviewer handoff linked from the thread.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 12 commits October 5, 2026 15:43
The composer's voice button statically imported MicrophonePreferences, which
put the preview UI on the SplitWorkspaceRoute closure and pushed it past its
raw budget. Wrap it in defineSplit with intent preloading, which shrinks the
closure from 1062.5 KiB to 1059.1 KiB, and revert the temporary 5% budget
increase from #4933.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SplitWorkspaceRoute closure moved whenever code shifted between the route
chunk and a page's own lazy chunk, even when the bytes a page waits for did
not change. Measure ThreadPage (route plus ThreadDetailView) and NewThreadPage
(route plus RootComposeView) as unions of their entries' static closures,
budget those, and point the split-boundary guards at both journeys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Splits declared one of four download policies, and startup or idle did nothing
unless a mounted owner also called useSplitPreload. Replace them with two
tiers: preload splits queue themselves when defined and drain at idle once
route content has painted; intent splits load on render or on their trigger's
intent events. Download-only warming joins the same queue, mount gating
(mountWhen, keepMounted, unmounted) replaces three hand-written gates, and the
remaining React.lazy feature boundaries below the router move to defineSplit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
client-core, thread-view and core-ui had no sideEffects declaration, so
Rolldown kept every module their index barrels re-export once boot imported a
single helper. Mark the three packages side-effect free. Boot drops by about
94 KB to 1398.0 KB; the ThreadPage and NewThreadPage journeys grow with the
code that now loads behind the route instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SplitThreadArea imported RootComposeView statically, so every thread page
waited for the new-thread composer, its pickers and setup dialogs. Load it
through a preload-tier split, preload it immediately on the root route, and
move the legacy project redirect out of the module so the route shell does not
import it. Make the thread detail split preload-tier as well, so each page
warms the other after first paint. ThreadPage drops from 1962.6 KB to 1807.3 KB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ServerMoveOverlay's polling, redirect and arrival handling must run from boot,
but its card, step list and recovery actions only render while a move is in
progress. Keep the logic eager and move the view into a preload-tier split so
it is downloaded shortly after first paint, before the old server can go
away mid-move. Boot drops by 8.2 KB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every page parsed sonner before first paint because appToast called it and
main.tsx mounted its Toaster eagerly. appToast now assigns toast IDs itself
and queues calls until the Toaster has mounted, which happens at idle after
route content paints or on the first toast. Plugin frontends wait for the
Toaster before running plugin code, since they call sonner directly. Boot
drops by 31.9 KB and sonner joins forbiddenBootPackages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Set ThreadPage and NewThreadPage limits 25% above their measured sizes after
the audit's cuts, and record the boot and journey reductions. The boot limits
stay where they were, which now leaves about 15% raw headroom.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The voice preferences popover used a single tall skeleton block while its
code loaded. Show the same PickerLoadingRows skeleton the model picker uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Route content was marked painted as soon as the route's loading skeleton
rendered, so preload-tier splits and plugin frontend boot started downloading
while the route and page chunks were still arriving and competed with them.
Track the route import, the current page's split and every render-triggered
split load as critical; drain the preload queue and mark route content painted
only once none are pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every page imports SplitWorkspaceRoute, but the import starts only after the
boot chunks have downloaded and run, so its files waited a full round trip
behind boot. Emit modulepreload links for the route chunk and the static
dependencies boot does not already load, so they download alongside boot.
On a throttled 300 ms / 10 Mbps profile the new-thread page shows content
about 340 ms sooner (4.40 s vs 4.74 s) with boot finishing at about the same
time; on a 150 ms / 200 KB/s profile it is about 170 ms sooner, with boot
finishing about 350 ms later because the two share bandwidth.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The banner stack above the new-thread composer hid itself with empty:hidden,
but a bare plugin banner that renders nothing still mounts an empty
display:contents root. That made the stack non-empty, so its 8px bottom
margin pushed the composer down when plugin frontends booted after first
paint. Hide the stack unless a direct child has content.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 839d668 into main Oct 5, 2026
34 checks passed
@ymichael
ymichael deleted the bb/bundle-headroom branch October 5, 2026 23:13
ymichael added a commit that referenced this pull request Oct 7, 2026
## Human comments

## What was wrong

PR #4782 was squash-merged from pushed head `6df2deeffa`, leaving four
subsequent local commits (`fdbbd8aea0`, `3f2def60ed`, `15648844c8`, and
`5b8191baf8`) unpublished. Settings therefore lacked the intended Voice
Input controls, and the microphone preview and warning feedback missed
the follow-up improvements.

## What changed

- Apply all four follow-ups onto current main (`452376e59e`): restore
Voice Input settings, open the shared preview from Settings, put warning
and hint on separate tooltip lines, show the active microphone in the
preview header, and shorten status messages to keep the popover steady.
- Resolve conflicts with #4955 by moving
`MicrophonePreferencesSplit.tsx` alongside the preview and retaining its
intent-based loading from both entry points. Keep the shared popover
shell separate from the heavy preview implementation.
- Preserve the microphone capture, reconnect, and late permission
cleanup tests at the preview's new location. Add a bundle boundary guard
for the implementation.
- Update configuration docs, CLI guide, and bb-cli reference for the
Settings entry point. No server/daemon wire, public SDK, or CLI command
changes; the device preference remains browser-local.

## How you verified

- `pnpm exec turbo run typecheck lint test --filter=@bb/app`: passed;
586 test files and 5,471 tests passed, with 2 files / 6 tests skipped.
Lint reported existing warnings and no errors.
- Focused preview, composer-button, and Settings tests after retaining
lifecycle coverage: 3 files / 11 tests passed. Final Turbo lint and
typecheck passed.
- `pnpm exec turbo run build --filter=@bb/app` and `node
apps/app/scripts/check-bundle-budget.mjs`: passed. Temporarily importing
the preview eagerly made the new boundary guard fail for
`MicrophonePreferences.tsx`; restoring the split and rebuilding passed.
- Isolated source app, connected local daemon, and Chromium
desktop/390px smoke checks: Settings opens the preview, device label
appears in the header, selection persists, capture tracks stop on close,
permission denial shows the compact hint, and the compact view uses the
shared drawer without hiding the app root. MediaDevices capture/device
scenarios used a browser-only synthetic audio stream; physical
microphone recording/transcription and iOS Simulator Safari were not
tested.
- `git diff --check`: passed. The verification inventory check reports
unrelated pre-existing drift: unmapped `browser` CLI family.

> AGENT GENERATED

---------

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