Skip to content

Split the icon map into a core boot map and a lazy extended registry (A14) - #1892

Merged
SawyerHood merged 2 commits into
bb/mobile-perf/katex-lazyfrom
bb/mobile-perf/icon-core-map
Aug 19, 2026
Merged

SawyerHood merged 2 commits into
bb/mobile-perf/katex-lazyfrom
bb/mobile-perf/icon-core-map

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

The shared Icon component kept one string-keyed map of 146 hugeicons entries in packages/shared-ui/src/components/ui/icon.tsx. The app shell imports it, so all ~100 KB raw (~20 KB brotli) of glyph arrays sat in the boot chunk of every page load. The shell paints only ~45 of those glyphs before a route renders. ICON_NAMES (used by PluginIcon to validate manifest icon hints) was derived from the map, which forced the whole map onto the boot path. Ten entries had no references anywhere in the repo. (Audit finding A14.)

What changed

  • icon.tsx keeps only the core map (sidebar rows and controls, header, toasts, menus, plugin chrome). IconName is CoreIconName | ExtendedIconName; ICON_NAMES is built from the core keys plus a names-only list, so validation does not load artwork.
  • New icon-extended.tsx holds the other 90 glyphs and registers them into new icon-registry.ts (names list + tiny subscribe/get store) when it evaluates.
  • Each lazy route module (SettingsView, ToolsView, MachineSettingsView, ProjectSettingsView, SplitWorkspaceRoute) imports @bb/shared-ui/icon-extended statically. Rolldown places the extended artwork in one shared chunk that Vite preloads with the route chunk, so route icons never flash.
  • Anywhere else (dialogs mounted from the shell, storybook, plugin bundles) Icon renders a same-size empty svg with data-icon-pending, calls preloadExtendedIcons() (idempotent import(), retried on failure) and re-renders through useSyncExternalStore once the registry lands. Core icons take no hook and do not re-render.
  • Pruned ten unreferenced names: AudioLines, BubbleChatQuestion, CalendarSync, ChatFeedback, CircleDashed, Container, FileX2, Idea, LightbulbOff, Rows3 (and their stale story captions).
  • packages/plugin-registry/scripts/build-registry.mjs now follows dynamic import() edges so a vendored @bb/icon keeps icon-extended/icon-registry; r/*.json and packages/templates starter files are regenerated.
  • apps/app/src/test/setup.ts preloads the extended registry so component tests see the same synchronous icons a mounted route does.
  • apps/app/bundle-budget.json ratcheted to 3% above the new measurement.

Boot payload measured on the app build: 1655.6 KB -> 1584.1 KB raw, 448.8 KB -> 435.3 KB brotli. The extended chunk is 66.6 KB raw / 14.5 KB brotli and loads with the first route.

How you verified

  • New apps/app/src/components/ui/icon.test.tsx (4 tests, fresh module graph per test): a core glyph renders synchronously with the registry still null; an extended glyph renders a 24x24 empty placeholder with data-icon-pending, then fills in after preloadExtendedIcons(); ICON_NAMES is the disjoint union of the core keys and the extended map keys and every extended name has artwork; icon.tsx reaches ./icon-extended only through import() and icon-registry.ts imports no artwork. The placeholder and static-graph tests fail on the old single-map module.
  • pnpm exec turbo run typecheck --filter='...@bb/shared-ui' (16 packages incl. @bb/app, @bb/templates with generator --check, @bb/plugin-registry, all plugins): pass.
  • pnpm exec turbo run test --filter=@bb/app --force: 364 files, 2891 passed, 3 skipped. --filter=@bb/templates --filter=@bb/plugin-registry: pass. --filter=@bb/cli -- plugin-build.test.ts plugin-scaffold-dependencies.test.ts (scaffold builds through esbuild with the dynamic import): pass. --filter=bb-plugin-tasks --filter=bb-plugin-side-chat --filter=@bb/plugin-build: pass, no act warnings.
  • pnpm exec turbo run lint --filter=@bb/app: 0 errors, 147 pre-existing warnings (same count as main).
  • pnpm exec turbo run build --filter=@bb/app --force then node apps/app/scripts/check-bundle-budget.mjs: boot 1584.1 KB raw / 435.3 KB brotli, 41 chunks, budget OK with the lowered ratchet.

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

Stack context

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

  • Prerequisite (layer below): bb/mobile-perf/katex-lazy (Lazy-load KaTeX in MarkdownPreview and guard on-demand packages in the bundle budget (A9) #1891).
  • Next layer: bb/mobile-perf/sidebar-defer-realize (Defer compact sidebar subtree realization inside the closed drawer (A7) #1893).
  • Audit findings addressed: see title IDs. Review: approved-with-fixes; 1 review fix commit(s).
  • Reviewer notes / follow-ups: Follow-up (not blocking): plugin bundles built with esbuild (no code splitting) inline import("./icon-extended") as Promise.resolve().then(init_icon_extended), so inside a plug | Follow-up (not blocking): the route preload relies on bare side-effect imports of @bb/shared-ui/icon-extended; if anyone later adds sideEffects: false to @bb/shared-ui (as A13 | Follow-up (not blocking): the on-demand loader retries on every render after a failed chunk fetch (same retry-on-failure pattern as plugin-frontend-lazy.ts, but triggered from rend
  • Wire/contract: None. No server<->daemon wire, protocol, route or command changes; HOST_DAEMON_PROTOCOL_VERSION untouched. Internal-only additions: @bb/shared-ui gains "./icon-extended" and "./icon-registry" export entries and Icon exports preloadExtendedIcons(); shared-ui is private and not part of the plugin SDK surface, so no experimental_ prefix or api_to_audit entry applies. Third-party plugins that pass one

AGENT GENERATED: by Claude Opus 5

@SawyerHood SawyerHood changed the title bb/mobile perf/icon core map Split the icon map into a core boot map and a lazy extended registry (A14) Aug 19, 2026
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/icon-core-map branch 2 times, most recently from 2bad9af to 3d8fd55 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/icon-core-map branch from 3d8fd55 to 45a625a Compare August 19, 2026 15:59
SawyerHood and others added 2 commits August 19, 2026 16:03
… registry

The shared `Icon` component kept one string-keyed map of 146 hugeicons
entries. Every route reaches it through the app shell, so all ~100 KB
raw of glyph arrays sat in the boot chunk of every page load, even
though the shell paints only ~45 of them before a route renders.

`icon.tsx` now holds only the core map (sidebar, header, toasts, menus,
plugin chrome). The remaining glyphs live in `icon-extended.tsx`, which
registers them into `icon-registry.ts` when it evaluates. Each lazy
route module imports it statically, so a route chunk ships the extended
artwork as one of its own preloaded deps and its icons never flash; for
anything else (dialogs mounted from the shell, storybook, plugins)
`Icon` renders a same-size empty svg, loads the registry on demand and
re-renders through `useSyncExternalStore`. `ICON_NAMES` (used by
PluginIcon to validate manifest hints) is built from a names-only list,
so validation keeps working without pulling the artwork onto the boot
path. Ten entries with no references anywhere in the repo are pruned
(AudioLines, BubbleChatQuestion, CalendarSync, ChatFeedback,
CircleDashed, Container, FileX2, Idea, LightbulbOff, Rows3).

The plugin component registry walker now follows dynamic `import()`
edges so a vendored `@bb/icon` keeps its extended registry; the
registry JSON and the plugin starter files are regenerated. The app
test setup preloads the extended registry so component tests see the
same synchronous icons a mounted route does; icon.test.tsx resets
modules to cover the cold placeholder path and guards the static import
graph of the boot modules.

Measured on the app build: boot payload 1655.6 KB -> 1584.1 KB raw and
448.8 KB -> 435.3 KB brotli; the extended chunk (66.6 KB / 14.5 KB br)
loads with the first route. bundle-budget.json is ratcheted to 3% above
the new measurement.

Co-Authored-By: Claude <[email protected]>
…e new registry modules

The placeholder test previously called preloadExtendedIcons() itself, so it
would still pass if Icon stopped requesting the registry on its own. It now
waits for the render-triggered load (fails in 5s without it) and checks the
idempotent preload afterwards. icon-extended.tsx / icon-registry.ts get
prettier-formatted, with the plugin registry and starter template regenerated
from them.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/icon-core-map branch from 45a625a to 6fe7622 Compare August 19, 2026 16:13
@SawyerHood
SawyerHood merged commit b856299 into main Aug 19, 2026
14 of 23 checks passed
@SawyerHood
SawyerHood deleted the bb/mobile-perf/icon-core-map branch August 19, 2026 16:23
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]>
SawyerHood added a commit that referenced this pull request Aug 19, 2026
…7) (#1893)

## What was wrong

On compact viewports `AppLayout` mounts the sidebar before the lazy
route element, and `SidebarMobilePanel` always rendered its children.
`ProjectList`, its DnD contexts, search hooks and slot subscriptions
therefore ran on the boot critical path for a panel that sits translated
off-screen and `inert` (audit finding A7).

## What changed

- `apps/app/src/components/ui/sidebar.tsx`: `SidebarProvider` owns a
one-shot realization latch (`isMobileSidebarRealized`). The panel
element stays mounted from the first commit (the swipe helpers select
it; no visibility flip, per #1261/#1356), but the compact `Sidebar`
renders its children only once the latch is set:
- `openMobileSidebar()` (trigger tap) realizes at slide start so the
subtree commits during the slide.
- The swipe path and direct `setOpenMobile(true)` callers realize in the
same render (render-time state adjust).
- A drawer that stays closed realizes from `requestIdleCallback` with a
1 s timeout; browsers without idle callbacks use two animation frames
plus the same 1 s timeout.
- The latch never resets, so app/settings/tools mode swaps and reopen
keep the retained subtree. Desktop renders children directly as before.

## How you verified

- New tests in `apps/app/src/components/ui/sidebar.test.tsx` (fail
before, pass after): closed panel is mounted, inert and empty at boot,
then realized in place after the settle window; `requestIdleCallback` is
preferred with `timeout: 1000` and frames alone do not realize; a
deferred open realizes before React state flips and content is retained
across close; desktop SSR renders children synchronously; swipe-open
realizes in the same commit.
- `pnpm exec turbo run test --filter=@bb/app --
src/components/ui/sidebar.test.tsx
src/components/layout/AppLayoutSidebar.test.tsx
src/components/plugin/PluginNavSidebarItems.test.tsx` and `--
src/components/layout/ src/components/sidebar/ ...`: all pass (37 files,
289 tests).
- `pnpm exec turbo run typecheck lint --filter=@bb/app`: pass; lint
warning count unchanged (148 before and after, none in sidebar.tsx).

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


## Stack context

Layer 14 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins
first, big rocks last).
- Prerequisite (layer below): `bb/mobile-perf/icon-core-map` (#1892).
- Next layer: `bb/mobile-perf/pierre-pool-and-route-closure` (#1894).
- Audit findings addressed: see title IDs. Review: approved.
- Wire/contract: None. No server/daemon wire, protocol version, CLI,
config, or plugin API changes. SidebarContext (internal, apps/app only)
gains `isMobileSidebarRealized: boolean`.

> 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