Skip to content

Boot payload quick wins: SDK guide, font preload, dark pre-paint, route preload + skeleton (A6, A8, A10, A13, A15, J1) - #1890

Merged
SawyerHood merged 7 commits into
bb/mobile-perf/http-caching-and-hub-gatingfrom
bb/mobile-perf/boot-shell-quickwins
Aug 19, 2026
Merged

SawyerHood merged 7 commits into
bb/mobile-perf/http-caching-and-hub-gatingfrom
bb/mobile-perf/boot-shell-quickwins

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

  • The browser SDK attached the guide area, so ~112 KB of generated guide markdown sat in the boot chunk although no browser code calls it (A8).
  • @bb/domain, @bb/server-contract and other leaf contract packages had no sideEffects: false, so barrel-reachable modules could not be dropped from the boot path (A13).
  • No font preload: the Inter latin woff2 request started only after the JS rendered text. --font-mono named the unshipped "Fira Code" (A15).
  • The pre-paint script never added the dark class or the cached palette CSS, so dark/themed sessions painted the light default palette until main.tsx ran (J1).
  • The * route chunk was fetched only on first React render and sat behind fallback={null}; the views then showed a bare "Loading…" paragraph (A6).
  • 24 desktop-app icon PNGs were base64-inlined into a route chunk (~35 KB br) for a menu that needs a local host daemon (A10).

What changed

  • createBbSdk takes the guide area as an explicit argument. The Node factory passes createGuideArea() and returns BbSdk; the browser factory returns BrowserBbSdk (all server-backed areas, no guide). The public-types test pins the browser key set. Plugin SDK bundled d.ts regenerated.
  • sideEffects: false on @bb/domain, @bb/server-contract, @bb/hono-typed-routes, @bb/host-daemon-contract, @bb/fuzzy-match.
  • New build-only Vite plugin bb:font-preload (apps/app/vite-font-preload.ts) injects <link rel="preload" as="font" type="font/woff2" crossorigin> for the emitted inter-latin-wght-normal asset. --font-mono is now the system monospace stack.
  • index.html: the head script adds dark per bb.theme / prefers-color-scheme; a body-end script injects bb.appThemeCss into <style id="bb-app-theme"> after the app stylesheet. applyCachedAppThemeCss adopts that element and re-appends it only when something was inserted after it (dev-mode style tags).
  • App.tsx starts import("./views/SplitWorkspaceRoute") at module scope and reuses the promise in lazy(). New RouteLoadingSkeleton (48 px header row + composer footprint) is the Suspense fallback for the * route and replaces the "Loading…" branches in RootComposeView and ThreadDetailView.
  • build.assetsInlineLimit excludes /workspace-open-target-icons/.
  • bundle-budget.json ratcheted to 3% above the new measurement.
  • A12 (chunk minSize) not applied: rolldown 1.0.0 only supports minSize for manual codeSplitting.groups; verified with a build that it has no effect on automatic boot chunks.

How you verified

  • pnpm exec turbo run build --filter=@bb/app then node apps/app/scripts/check-bundle-budget.mjs: boot payload 1538.4 KB raw / 415.5 KB brotli, 41 chunks (before: budget 1671 / 456.4). dist/index.html contains the font preload link; root-compose-create-preference-*.js is 4,253 B; the entry chunk references the SplitWorkspaceRoute chunk statically.
  • pnpm exec turbo run typecheck --filter=@bb/sdk --filter=@bb/app --filter=@bb/cli --filter=@bb/server --filter=bb-app --filter=@get-bb/plugin-sdk: pass.
  • pnpm exec turbo run lint --filter=@bb/app --filter=@bb/sdk: 0 errors (147 pre-existing warnings, none in touched files).
  • New tests: apps/app/src/index-html-pre-paint.test.ts (7 tests: runs the real index.html inline scripts under jsdom; dark class from stored/system preference; palette style injected as last head child; adoption by applyCachedAppThemeCss) and apps/app/src/vite-font-preload.test.ts (3 tests). Also ran theme.test.ts, App.* route tests, RootComposeView/SplitWorkspaceRoute/SplitThreadArea tests, full @bb/sdk suite (94 tests), CLI guide tests: all pass.

Fixes: part of the mobile / iOS Safari performance program (verified sweep report in the bb thread; no single issue).

Stack context

Layer 11 of 22 in the bb/mobile-perf/* stack (bottom → top: quick wins first, big rocks last).

  • Prerequisite (layer below): bb/mobile-perf/http-caching-and-hub-gating (API brotli, cache validators, bfcache-friendly index and hub gating (B22, D8, I5, J5, B17) #1889).
  • Next layer: bb/mobile-perf/katex-lazy (Lazy-load KaTeX in MarkdownPreview and guard on-demand packages in the bundle budget (A9) #1891).
  • Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s).
  • Deliberately not done here: A12: rolldown 1.0.0 (Vite 8.0.12) exposes codeSplitting.minSize only as a fallback for manual groups, not as a minimum for automatic chunks; verified by build t
  • Reviewer notes / follow-ups: A12 (chunk minSize) intentionally skipped by the implementer; rolldown's codeSplitting.minSize is a fallback-group setting and did not change the boot graph. Not a defect, just uni | Minor, not fixed: the font is injected with injectTo:"head" so it lands as the last head child, after ~40 modulepreload links and the stylesheet. Preload scanner | Pre-existing, not a regression: the root "@bb/sdk" export maps the browser condition to dist/browser.js while its "types" point at node.ts (BbSdk with guide). apps/app only type-im
  • Wire/contract: None. No server<->daemon payloads, host RPC, or WebSocket messages changed; HOST_DAEMON_PROTOCOL_VERSION not bumped. Type-level contract change only: @bb/sdk BbSdk is now BbSdkAreas + guide; createBrowserBbSdk() returns BrowserBbSdk (no guide). No browser caller used sdk.guide. bundled-types/bb-plugin-sdk.d.ts regenerated.

AGENT GENERATED: by Claude Opus 5

@SawyerHood SawyerHood changed the title bb/mobile perf/boot shell quickwins Boot payload quick wins: SDK guide, font preload, dark pre-paint, route preload + skeleton (A6, A8, A10, A13, A15, J1) Aug 19, 2026
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/boot-shell-quickwins branch 2 times, most recently from 0dc1cfd to d604f89 Compare August 19, 2026 07:50
@SawyerHood
SawyerHood marked this pull request as ready for review August 19, 2026 08:04
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/boot-shell-quickwins branch from d604f89 to de4b169 Compare August 19, 2026 15:59
SawyerHood and others added 7 commits August 19, 2026 16:03
The browser SDK factory attached the `guide` area, whose module imports
`@bb/templates/generated` and builds a Map of every template body at boot.
No browser code calls `sdk.guide`, yet the generated markdown (~112 KB raw,
~30-37 KB brotli, about 7% of the compressed boot payload) landed in the web
app's boot chunk on every cold load.

`createBbSdk` now takes the guide area as an explicit argument: the Node
factory passes `createGuideArea()` and returns the full `BbSdk`; the browser
factory omits it and returns `BrowserBbSdk` (= `BbSdkAreas`, every
server-backed area without `guide`). The `bb guide` command and the public
`bb-app` SDK keep the same synchronous, template-only guide. The plugin SDK's
bundled declaration file is regenerated for the split interface, and the
public-types test pins the browser instance to the guide-less key set.

Co-Authored-By: Claude <[email protected]>
@bb/domain, @bb/server-contract, @bb/hono-typed-routes,
@bb/host-daemon-contract and @bb/fuzzy-match only export schemas, types and
pure helpers; nothing imports them for side effects and no module registers
anything at load time. Without the flag the bundler has to keep every module
reachable through their barrels on the boot path even when only a type or a
single helper is used. Validation behavior is unchanged: modules that are
actually imported still evaluate exactly as before.

Co-Authored-By: Claude <[email protected]>
The app declares seven Inter @font-face subsets with font-display: swap but
never preloads any of them, and #root is empty until React renders, so the
font request only starts after ~1.5 MB of JavaScript has parsed and the
first text node needs it. A build-only Vite plugin (bb:font-preload) now
finds the emitted latin upright variable subset in the output bundle and
injects `<link rel="preload" as="font" crossorigin>` for it; the other
subsets stay lazy. Emitting from the bundle keeps the preload URL identical
to the CSS url() so the browser makes one CORS-mode fetch.

--font-mono named "Fira Code", which is not shipped, so every browser first
looked up a font that only exists on a few developer machines. The token now
uses the system monospace stack.

This commit also adds the assetsInlineLimit exclusion for the desktop-app
icons (see the following budget commit for the measured effect).

Co-Authored-By: Claude <[email protected]>
theme.css keys every dark token off the `dark` class, and palettes such as
Nord or Dracula are `:root`/`.dark` overrides injected by applyAppThemeCss.
Both were applied from main.tsx, after the boot chunks downloaded and
evaluated, so a dark or themed session painted the light default palette
first on every cold load; on a phone that white flash lasts as long as the
JavaScript takes to arrive.

The head inline script now resolves the same `bb.theme` preference it
already used for the theme-color meta and adds the `dark` class before the
stylesheet applies. A second inline script at the end of <body> injects the
`bb.appThemeCss` cache into `<style id="bb-app-theme">` after the app
stylesheet link, where its overrides win by source order.
applyCachedAppThemeCss adopts that element and re-appends it only when
something (the dev server's style tags) was inserted after it.

The new test runs the real inline scripts from index.html under jsdom with
the storage keys and writer from useTheme.ts / lib/themes, so a renamed key
or a changed cache shape fails the test instead of silently bringing the
flash back.

Co-Authored-By: Claude <[email protected]>
…loads

The `*` route's chunk was fetched only when the first React render reached
`lazy()`, so its ~880 KB brotli closure started downloading one boot parse
and one render after the boot chunks finished. Meanwhile the content area
sat behind `fallback={null}`, and once the chunk arrived the views showed a
bare centered "Loading…" paragraph.

App.tsx now starts the `import()` at module scope and hands the same promise
to `lazy()`, so the request (and Vite's modulepreload of the closure) begins
as soon as the boot chunk evaluates. A RouteLoadingSkeleton (48 px header
row on the shared chrome axis plus the composer footprint) is the Suspense
fallback for that route and replaces the "Loading…" branches in
RootComposeView and ThreadDetailView, so the page keeps one silhouette from
first paint until real content mounts. Settings and tools routes keep the
null fallback because AppLayout already renders their header.

Co-Authored-By: Claude <[email protected]>
Measured after `pnpm exec turbo run build --filter=@bb/app`: 1,575,323 B raw
/ 425,468 B brotli across 41 boot chunks (was ~1,661 KB / ~453 KB). The
desktop-app icons excluded from inlining in vite.config.ts shrink the
root-compose-create-preference route chunk from 54,340 B (34,947 B br) to
4,253 B (1,866 B br); the guide templates leave the atomFamily boot chunk.
maxBootBytes / maxBootBrotliBytes are set 3% above the new measurement per
the ratchet rule in the file.

Co-Authored-By: Claude <[email protected]>
The public-types test only checks the declared shape of each SDK. Add a
runtime test that createNodeBbSdk attaches a working guide and
createBrowserBbSdk does not, so wiring createGuideArea() back into the
shared core fails fast instead of only after a full build in the
bundle-budget check.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/boot-shell-quickwins branch from de4b169 to 5346028 Compare August 19, 2026 16:13
@SawyerHood
SawyerHood merged commit e254162 into main Aug 19, 2026
14 of 23 checks passed
@SawyerHood
SawyerHood deleted the bb/mobile-perf/boot-shell-quickwins branch August 19, 2026 16:23
SawyerHood added a commit that referenced this pull request Aug 19, 2026
…B22, D8, I5, J5, B17) (#1889)

## What was wrong

- API JSON was gzip-only through hono/compress. It never set Vary and
its 1 KB threshold did not apply because Hono JSON has no
Content-Length, so every body streamed through gzip. Brotli saves 10-20%
on the timeline and sidebar payloads a phone downloads per turn.
- Attachment content had no cache headers although stored names are
immutable. Host-file responses ignored the sha256/mtime the daemon
returns. iOS purges the memory cache on backgrounding, so PWA relaunches
re-downloaded multi-megabyte screenshots. The SDK also copied every
upload through arrayBuffer() and the composer preview re-downloaded the
image it had just uploaded.
- index.html and all public icons/manifests were served no-store.
no-store blocks the WebKit back/forward cache, and icons were refetched
on every favicon flip and never edge-cached. The favicon code re-decoded
both PNGs on every badge flip, even in an installed PWA where no tab
icon exists.
- The plugin-frontend pagehide handler tore everything down even for a
bfcache freeze and had no pageshow reboot.
- Every thread-list subscriber received every thread's raw
events-appended stream (~10 frames/s per streaming thread) and ran cache
walks for threads it was not viewing.

## What changed

- New apps/server/src/api-response-compression.ts buffers core /api/v1
JSON (not plugin bb.http handlers, not /internal streaming) and sends
Brotli q4 or gzip with exact Content-Length and Vary: Accept-Encoding;
sub-1 KB bodies stay identity. It runs inside the existing streaming
gzip fallback.
- Attachment content: private, immutable, max-age=31536000 + ETag +
Content-Length + 304. Daemon file responses: ETag (sha256),
Last-Modified, Content-Length, default private, no-cache, 304 on
If-None-Match; content routes pass If-None-Match through. SDK passes
Blob/File to FormData directly. Composer keeps an object URL for a
just-picked image (revoked on remove). Images use decoding="async".
- index.html: no-cache. Non-HTML public files: public, max-age=86400.
Favicon base glyphs memoized; favicon work skipped in standalone display
mode.
- Plugin frontends tear down only on a non-persisted pagehide; a
persisted pageshow reconciles or reboots.
- Hub: thread-detail subscribers get every events-appended frame;
thread-list-only sockets get the first frame at once and one merged
frame per 1 s window per thread. Frames with list-relevant metadata or
other change kinds bypass coalescing.

## How you verified

- New tests: apps/server/test/app/api-json-compression.test.ts (br +
Content-Length + Vary, gzip fallback and q=0, identity below threshold,
plugin/internal paths not buffered, real /api/v1/system/config);
apps/server/test/hosts/daemon-file-response.test.ts (validators, caller
headers kept, 304, If-None-Match matching);
apps/server/test/app/hub.test.ts (detail vs list-only fan-out, trailing
merged frame, bypass rules, per-thread windows, waiters and listeners);
apps/app/src/components/promptbox/AttachmentPreview.test.tsx (object-URL
src, fallback URL, decoding=async, revoke on remove);
apps/app/src/lib/favicon-color-preference.test.ts (one decode per glyph,
standalone skip); apps/app/src/lib/plugin-frontend.test.ts (page
lifecycle policy).
- Updated tests: static-cache.test.ts (no-cache index, max-age=86400
icons/manifest), public-project-attachments.test.ts (cache headers,
ETag, 304).
- pnpm exec turbo run typecheck --filter=@bb/app --filter=@bb/sdk
--filter=@bb/server: pass. lint: 0 errors. Full @bb/server and @bb/sdk
suites: all pass except a pre-existing umask-dependent
internal-skill-trees test that also fails on baseline.

Fixes: part of the mobile / iOS Safari performance program (verified
sweep report in the bb thread; no single issue).


## Stack context

Layer 10 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins
first, big rocks last).
- Prerequisite (layer below):
`bb/mobile-perf/timeline-delta-ring-and-output-cap` (#1888).
- Next layer: `bb/mobile-perf/boot-shell-quickwins` (#1890).
- Audit findings addressed: see title IDs. Review: approved-with-fixes;
2 review fix commit(s).
- Reviewer notes / follow-ups: Minor (not fixed, by design/bounded):
apps/app/src/lib/attachment-local-previews.ts keeps up to 24 object URLs
(and thus the picked File/Blob) alive after a draft is sent; only rem |
Behavioral note (documented by implementer): SDK/plugin `thread:changed`
subscribers without a threadId (thread-list channel) now receive plain
events-appended at leading edge + on | Pre-existing, unrelated:
apps/server/src/server.ts fails the root eslint `no-restricted-imports`
rule for node:fs/promises (present at base dde6cdd; @bb/server has no
lint task s
- Wire/contract: None on the server<->daemon wire
(HOST_DAEMON_PROTOCOL_VERSION not bumped): daemon-file-response only
consumes fields the daemon already returns (sha256, modifiedAtMs).
Client-facing HTTP: API JSON may now be Content-Encoding: br with
Content-Length + Vary; attachment content and host-file routes gain
ETag/Last-Modified/Cache-Control/Content-Length and can answer 304;
index.html no-cache; public f

> 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
…e bundle budget (A9) (#1891)

## What was wrong

`apps/app/src/components/ui/markdown-preview.tsx` imported
`rehype-katex` and `katex/dist/katex.min.css` statically. The
`katex-*.js` chunk (259,230 B raw / 64,287 B brotli) plus its CSS was a
static edge of the thread route closure. Every thread downloaded and
parsed the math renderer before first paint. Almost no message contains
`$$` math. Nothing in CI could catch a regression:
`check-bundle-budget.mjs` only inspects the boot closure, and the thread
route is a lazy chunk.

## What changed

- `markdown-katex.ts` (new): the only module that imports `rehype-katex`
and the KaTeX stylesheet.
- `markdown-katex-loader.ts` (new): cached
`import("./markdown-katex.js")`, a `useSyncExternalStore` hook that
returns the plugin once loaded, and `markdownMayContainMath`
(`content.includes("$$")`; with `singleDollarTextMath: false` this is
the only way to produce a math node).
- `markdown-preview.tsx`: `remark-math` stays static. The rehype chain
is `[rehypeRaw, rehypeSanitize]` or `[]`, with `rehypeKatex` appended
only after the chunk resolves. Ordering (KaTeX after sanitize) is
unchanged.
- `vite-bundle-stats.ts`: also writes `chunks[]` (every JS chunk with
static `imports`, `packages`, and `facade` module) alongside
`bootChunks`.
- `bundle-budget.json` + `scripts/check-bundle-budget.mjs`:
`onDemandPackages` maps `katex` and `rehype-katex` to
`src/components/ui/markdown-katex.ts`. The check fails when any chunk
outside that gate's static closure reaches the package, or when the gate
chunk is missing. The script takes an optional budget directory argument
for tests.

## How you verified

- `pnpm exec turbo run test --filter=@bb/app --
src/check-bundle-budget.test.ts
src/components/ui/markdown-katex-loader.test.tsx
src/components/ui/markdown-preview.test.tsx`: 20 passed.
- `markdown-katex-loader.test.tsx`: content without `$$` never triggers
the chunk import; two mounted previews with math load the chunk once and
both re-render with `.katex`; a later preview gets it synchronously.
- `check-bundle-budget.test.ts`: fixture graph passes when katex is only
behind the gate; fails naming `route.js, markdown-preview.js` when
markdown-preview imports the katex chunk statically; fails when the gate
module is absent.
- Existing KaTeX tests in `markdown-preview.test.tsx` now `waitFor` the
lazy chunk.
- `pnpm exec turbo run build --filter=@bb/app` then `node
apps/app/scripts/check-bundle-budget.mjs`: "Bundle budget OK" (boot
1655.6 KB raw / 448.8 KB br). Graph inspection: `SplitWorkspaceRoute`
closure no longer contains `katex`; `markdown-katex-*.js` (15.7 KB,
facade `src/components/ui/markdown-katex.ts`) statically imports
`katex-*.js`; the KaTeX CSS is now its own `markdown-katex-*.css` chunk.
- `pnpm exec turbo run typecheck lint --filter=@bb/app`: pass
(pre-existing React Compiler warnings only, none in touched files).

Fixes: part of the mobile / iOS Safari performance program (verified
sweep report in the bb thread; no single issue).


## Stack context

Layer 12 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins
first, big rocks last).
- Prerequisite (layer below): `bb/mobile-perf/boot-shell-quickwins`
(#1890).
- Next layer: `bb/mobile-perf/icon-core-map` (#1892).
- Audit findings addressed: see title IDs. Review: approved.
- Reviewer notes / follow-ups: Minor UX (accepted trade-off, not fixed):
the first time a session renders `$$` math, the display-math block
flashes as a `MATH` fenced-code block (header + copy button) until the |
Nit: apps/app/src/check-bundle-budget.test.ts leaves its mkdtemp
directories in os.tmpdir() (no cleanup). Harmless.
- Wire/contract: None. No server/daemon wire, protocol version, CLI, or
plugin API changes. bundle-stats.json (gitignored build artifact) gains
a `chunks` array; bundle-budget.json gains `onDemandPackages`;
check-bundle-budget.mjs accepts an optional second argv (budget/stats
directory) — additive, CI invocation unchanged.

> AGENT GENERATED: by Claude Code (claude-mangosteen-eap)

---------

Co-authored-by: Claude <[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