Repository navigation
Defer compact sidebar subtree realization inside the closed drawer (A7) - #1893
Merged
SawyerHood merged 1 commit intoAug 19, 2026
Merged
SawyerHood merged 1 commit into
SawyerHood merged 1 commit into
Conversation
SawyerHood
force-pushed
the
bb/mobile-perf/sidebar-defer-realize
branch
2 times, most recently
from
August 19, 2026 07:50
3abcc30 to
78c3cc6
Compare
SawyerHood
marked this pull request as ready for review
August 19, 2026 08:04
SawyerHood
force-pushed
the
bb/mobile-perf/sidebar-defer-realize
branch
from
August 19, 2026 15:59
78c3cc6 to
13c5b5a
Compare
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
force-pushed
the
bb/mobile-perf/sidebar-defer-realize
branch
from
August 19, 2026 16:13
13c5b5a to
b26fa0d
Compare
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]>
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
On compact viewports
AppLayoutmounts the sidebar before the lazy route element, andSidebarMobilePanelalways 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 andinert(audit finding A7).What changed
apps/app/src/components/ui/sidebar.tsx:SidebarProviderowns 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 compactSidebarrenders its children only once the latch is set:openMobileSidebar()(trigger tap) realizes at slide start so the subtree commits during the slide.setOpenMobile(true)callers realize in the same render (render-time state adjust).requestIdleCallbackwith a 1 s timeout; browsers without idle callbacks use two animation frames plus the same 1 s timeout.How you verified
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;requestIdleCallbackis preferred withtimeout: 1000and 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.tsxand-- 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).bb/mobile-perf/icon-core-map(Split the icon map into a core boot map and a lazy extended registry (A14) #1892).bb/mobile-perf/pierre-pool-and-route-closure(Gate the pierre worker pool and trim/ratchet the SplitWorkspaceRoute closure (A2, A1) #1894).isMobileSidebarRealized: boolean.