Skip to content

Defer compact sidebar subtree realization inside the closed drawer (A7) - #1893

Merged
SawyerHood merged 1 commit into
bb/mobile-perf/icon-core-mapfrom
bb/mobile-perf/sidebar-defer-realize
Aug 19, 2026
Merged

SawyerHood merged 1 commit into
bb/mobile-perf/icon-core-mapfrom
bb/mobile-perf/sidebar-defer-realize

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

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 Large active thread lists keep all sidebar rows mounted #1261/Speed up iOS Safari drawer interactions #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).

AGENT GENERATED: by Claude Opus 5

@SawyerHood SawyerHood changed the title Defer compact sidebar subtree realization inside the closed inert panel Defer compact sidebar subtree realization inside the closed drawer (A7) Aug 19, 2026
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/sidebar-defer-realize branch 2 times, most recently from 3abcc30 to 78c3cc6 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/sidebar-defer-realize branch from 78c3cc6 to 13c5b5a Compare August 19, 2026 15:59
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.

SidebarProvider now owns a one-shot realization latch for the compact
drawer. The panel element stays mounted from the first commit (the swipe
helpers select it and there is no visibility flip, per #1261/#1356), but
its subtree renders only once the latch is set: on the first open (the
deferred trigger open realizes at slide start; the swipe path and direct
setOpenMobile(true) callers realize in the same render) or, for a drawer
that stays closed, from requestIdleCallback with a 1 s timeout (two
animation frames plus the same timeout where idle callbacks are missing).
Once set the latch never resets, so mode swaps (app/settings/tools) and
reopen keep the retained subtree. Desktop is unchanged.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/sidebar-defer-realize branch from 13c5b5a to b26fa0d Compare August 19, 2026 16:13
@SawyerHood
SawyerHood merged commit 01c337a into main Aug 19, 2026
14 of 23 checks passed
@SawyerHood
SawyerHood deleted the bb/mobile-perf/sidebar-defer-realize branch August 19, 2026 16:23
SawyerHood added a commit that referenced this pull request Aug 19, 2026
…(A14) (#1892)

## 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` (#1891).
- Next layer: `bb/mobile-perf/sidebar-defer-realize` (#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 Code (claude-mangosteen-eap)

---------

Co-authored-by: Claude <[email protected]>
SawyerHood added a commit that referenced this pull request Aug 19, 2026
…closure (A2, A1) (#1894)

## What was wrong

Every routed pane sits under `ThreadDetailWorkerPoolProvider`.
`@pierre/diffs` constructs its `WorkerPoolManager` when the provider
mounts, and the constructor spawns every worker (each ~830 KB of
JavaScript plus a Shiki heap). So the root compose page and threads with
no diff spawned `min(8, cores - 1)` workers on first thread paint.
`PluginPanelView` mounted a second provider on top, and the theme sync
called `pool.setRenderOptions` with the constructor theme on mount.

`SplitWorkspaceRoute` (every thread, compose and plugin-panel page) had
a static-import closure of 33 chunks, 3.45 MB raw / 893 KB brotli. It
reached `@pierre/diffs` + Shiki, KaTeX, xterm and the whole secondary
panel, browser deck and new-tab page before any user action. Only the
boot payload was measured, so nothing stopped the closure from growing.

## What changed

- The workspace provider publishes the pool through an app-owned gate
context and builds it only after the first diff consumer calls
`useRequirePierreWorkerPool()`. The pool manager, workers and theme sync
live in a lazily loaded chunk. The provider imports nothing from
`@pierre/diffs` at runtime: importing even pierre's `WorkerPoolContext`
object statically drags the pool manager and Shiki into the route,
because that module also defines pierre's provider. Consumers hand the
pool to pierre through `PierreWorkerPoolBoundary` and render pierre only
once the gate is ready (pierre captures the pool when it creates a diff
instance). The plugin runtime hands plugins gated pierre components;
`WorkerPoolContextProvider` and `useWorkerPool` resolve to the host
pool.
- `getDiffWorkerPoolSize` caps at 2 on `(pointer: coarse)` or
`navigator.deviceMemory <= 4`, and at 4 elsewhere (was 8). The theme
sync tracks the applied pair per pool and skips redundant
`setRenderOptions`. The duplicate provider in `PluginPanelView` is gone.
- `lazySecondaryPanelComponents.tsx` wraps ThreadSecondaryPanel,
ThreadTerminalPanel, BrowserTabDeck, NewTabPage, FilePreview and the
file-preview tab contents in `React.lazy` with local Suspense
boundaries. Compact drawers realize them on first open. Inline hosts
show a placeholder `Panel` with the real panel's id, order, size and
bounds so the layout does not shift when the chunk lands.
`TimelineFileDiffBlock` and `rehype-katex` (with its CSS) load on
demand.
- `vite-bundle-stats` records each measured lazy route's static closure
minus the boot chunks. `check-bundle-budget.mjs` ratchets it with its
own forbidden list (`routeClosures` in `bundle-budget.json`).
`why-eager.mjs --from=<module>` explains a route closure.

Route closure before: 3,451,217 B raw / 893,719 B brotli, 33 chunks.
After: 2,377,618 B raw / 640,813 B brotli, 35 chunks (-31% raw, -28%
brotli). No `@pierre/diffs`, Shiki, KaTeX or xterm remain. Budget set 3%
above: 2,449,000 / 660,100.

## How you verified

- New tests: `diff-worker-pool.test.ts` (pool size caps),
`pierre-worker-pool-theme.test.tsx` (no `setRenderOptions` when
unchanged, once per change, catch-up for a stale pool),
`ThreadDetailWorkerPoolProvider.test.tsx` (no pool until a consumer
asks; consumer waits then sees the pool; siblings do not remount;
no-Worker path; release on unmount), `plugin-frontend.test.ts` (slot
export parity with `@pierre/diffs/react`, gated components),
`bundle-budget.test.ts` (route closure excludes boot and dynamic-only
chunks; the check script passes, fails on a forbidden route package,
fails on route bytes over budget). `markdown-preview.test.tsx` KaTeX
cases now await the lazy chunk.
- `pnpm exec turbo run typecheck --filter=@bb/app`, `pnpm exec turbo run
lint --filter=@bb/app` (0 errors), `pnpm exec turbo run build
--filter=@bb/app` then `node apps/app/scripts/check-bundle-budget.mjs`
(Bundle budget OK), targeted vitest runs (114 files / 929 tests over
secondary-panel, views, timeline, plugin, git-diff, markdown-preview and
the new tests) all pass. Commit 1 was also typechecked and tested in
isolation.

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


## Stack context

Layer 15 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins
first, big rocks last).
- Prerequisite (layer below): `bb/mobile-perf/sidebar-defer-realize`
(#1893).
- Next layer: `bb/mobile-perf/plugin-build-minify` (#1895).
- Audit findings addressed: see title IDs. Review: approved-with-fixes;
1 review fix commit(s).
- Deliberately not done here: A1 step (d) tiptap first-focus deferral:
out of scope per assignment (composer visible; tiptap allowed in the
route forbidden list)
- Reviewer notes / follow-ups: Follow-up (not a defect): on phones the
ThreadSecondaryPanel chunk is now fetched on the first drawer open
(inside the persistent drawer, after realization), so a cold-cache first
| Follow-up (by design of A2): the first file preview / diff on a page
now also waits for the pool chunk plus worker init instead of a
pre-warmed pool; FilePreview's existing 'wait f | Follow-up already
noted by the implementer: SplitWorkspaceRoute chunk (620 KB) still
carries handlebars/source-map via @bb/templates and preact via
@pierre/trees; workspace-checkou
- Wire/contract: None. No server/daemon wire, host RPC, or protocol
changes; HOST_DAEMON_PROTOCOL_VERSION unchanged. Plugin runtime shim
slot `pierreDiffsReact` keeps the same export names;
FileDiff/File/MultiFileDiff/PatchDiff/UnresolvedFile/CodeView are now
gated wrappers, WorkerPoolContextProvider is a host passthrough and
useWorkerPool returns the host pool (plugin design 5.5: host owns the
pool). check-bundle

> 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