Skip to content

Gate the pierre worker pool and trim/ratchet the SplitWorkspaceRoute closure (A2, A1) - #1894

Merged
SawyerHood merged 4 commits into
bb/mobile-perf/sidebar-defer-realizefrom
bb/mobile-perf/pierre-pool-and-route-closure
Aug 19, 2026
Merged

SawyerHood merged 4 commits into
bb/mobile-perf/sidebar-defer-realizefrom
bb/mobile-perf/pierre-pool-and-route-closure

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

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 (Defer compact sidebar subtree realization inside the closed drawer (A7) #1893).
  • Next layer: bb/mobile-perf/plugin-build-minify (Minify plugin app bundles, optimize their CSS, drop provider plugin app bundles (A4, H7) #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 Opus 5

@SawyerHood SawyerHood changed the title bb/mobile perf/pierre pool and route closure Gate the pierre worker pool and trim/ratchet the SplitWorkspaceRoute closure (A2, A1) Aug 19, 2026
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/pierre-pool-and-route-closure branch from 95f0b4b to 4728ddd Compare August 19, 2026 07:42
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/pierre-pool-and-route-closure branch from 4728ddd to 9e75f96 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/pierre-pool-and-route-closure branch from 9e75f96 to 92eec8e Compare August 19, 2026 15:59
SawyerHood and others added 4 commits August 19, 2026 16:03
Every routed pane sits under ThreadDetailWorkerPoolProvider, and
@pierre/diffs constructs its WorkerPoolManager (which spawns every worker,
each ~830 KB of JavaScript plus a Shiki heap) the moment the provider
mounts. So the root compose page and threads with no diff at all spawned
min(8, cores - 1) workers on first thread paint, and PluginPanelView
mounted a second provider on top. useSyncPierreWorkerPoolTheme also called
pool.setRenderOptions with the constructor theme on mount, which
initializes the pool before comparing options.

- ThreadDetailWorkerPoolProvider now publishes the pool through the app's
  own gate context and builds it only after a diff consumer asks through
  useRequirePierreWorkerPool. It imports nothing from @pierre/diffs at
  runtime: the pool manager, the workers and the theme sync live in the
  lazily loaded lib/pierre-worker-pool chunk. (Importing even pierre's
  WorkerPoolContext object statically drags the pool manager and Shiki
  along, because that module also defines pierre's provider.) The child
  tree keeps its position, so nothing remounts when the pool arrives.
- Consumers hand the pool to pierre through PierreWorkerPoolBoundary right
  around the diff element, and render it only once the gate is ready,
  because pierre captures the pool when it creates a diff instance:
  GitDiffCardBody's DiffView, FilePreview's PierreFile, and the diff
  components handed to plugin bundles through the runtime shim (named
  imports, so a namespace import cannot mark pierre's provider as used;
  the shim's WorkerPoolContextProvider and useWorkerPool now resolve to the
  host pool).
- getDiffWorkerPoolSize caps the pool at 2 on (pointer: coarse) or
  navigator.deviceMemory <= 4 GB and at 4 elsewhere (was 8).
- The theme sync tracks the pair each pool renders with and skips
  setRenderOptions when unchanged.
- The duplicate provider in PluginPanelView is removed; every plugin panel
  is a pane of the split workspace.

Co-Authored-By: Claude <[email protected]>
SplitWorkspaceRoute (every thread, compose and plugin-panel page) had a
static-import closure of 33 chunks, 3.45 MB raw / 893 KB brotli, that a
phone must download and parse between the app shell and the first thread
paint. It reached @pierre/diffs + Shiki (through FilePreview, the timeline
diff block and the worker-pool provider), KaTeX (through MarkdownPreview),
xterm (through ThreadTerminalPanel) and the whole secondary panel, browser
deck and new-tab page, none of which the route renders before a user
action. Only the boot payload was measured, so nothing stopped it growing.

- lazySecondaryPanelComponents.tsx wraps ThreadSecondaryPanel,
  ThreadTerminalPanel, BrowserTabDeck, NewTabPage, FilePreview and the file
  preview tab contents in React.lazy with their own Suspense boundaries;
  ThreadDetailView, RootComposeView, the two secondary-content views and
  PluginPanelRightPanelHost (which had private copies) render those. On
  compact viewports the drawer realizes 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. The sizing constants
  the route needs move to the leaf secondaryPanelSizing.ts.
- TimelineRowDetails renders TimelineFileDiffBlock through a lazy wrapper,
  so pierre's parser and FileDiff load with the first file-change row.
- MarkdownPreview loads rehype-katex (and its stylesheet) on demand through
  markdown-katex-loader when a body contains "$$"; remark-math stays
  static. Math shows its source until the chunk lands, then re-renders.
- 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), and why-eager.mjs
  takes --from=<module> to explain a route closure. Budget set 3% above
  the measured 2,377,618 B raw / 640,813 B brotli (35 chunks), down from
  3,451,217 B / 893,719 B (33 chunks); the closure no longer contains
  @pierre/diffs, Shiki, KaTeX or xterm. tiptap stays allowed for now (the
  composer is visible on every thread page).

Co-Authored-By: Claude <[email protected]>
The split-workspace host and the lazy placeholder now read the panel bounds
from the secondaryPanelSizing leaf; nothing imports them from
ThreadSecondaryPanel any more, and keeping the re-export invites a future
importer to pull the lazily loaded panel back into the route closure.

Co-Authored-By: Claude <[email protected]>
Stacked on the katex-lazy, icon-registry and sidebar-defer layers, the
SplitWorkspaceRoute closure measures 2,484,528 B raw / 651,153 B brotli
(36 chunks); the raw ratchet set on the unstacked branch was 34.7 KB
under that. Reset both route limits to 3% above the measured values.
The boot budget already fits and is unchanged.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/mobile-perf/pierre-pool-and-route-closure branch from 92eec8e to 3f9d986 Compare August 19, 2026 16:13
@SawyerHood
SawyerHood merged commit 9c7cccf into main Aug 19, 2026
12 checks passed
@SawyerHood
SawyerHood deleted the bb/mobile-perf/pierre-pool-and-route-closure branch August 19, 2026 16:23
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]>
SawyerHood added a commit that referenced this pull request Aug 19, 2026
…pp bundles (A4, H7) (#1895)

## What was wrong

Plugin frontend bundles were built without minification, and every
plugin's `app.css` carried the Tailwind utilities of all of
`@bb/shared-ui`: `bb.pluginTailwindContent: ["src/**/*"]` fed the whole
package glob to the scanner whether or not the plugin imported those
components (~110 KB / ~1200 rules per sheet, plus a `:root` block that
re-declared the host's semantic token bridge). On phones the raw bytes
drive parse time, each stylesheet insertion is a document-wide restyle,
and ~17k scoped rules stay resident. (A4)

Four first-party provider plugins (claude-code, codex, pi, acp) shipped
an app bundle whose only job was to register, through
`experimental_providerIcon`, an SVG byte-identical to the one the host
already vendors in `BUILT_IN_BRAND_ICONS`: four JS fetches, four CSS
fetches, four stylesheet inserts and four icon remounts per page load
for no visible change. (H7)

## What changed

- `buildPluginApp` builds with `minify: true`, `legalComments: "none"`,
and takes `{ minify }`; `bb plugin dev` passes `{ minify: false }` so
stack traces and CSS stay readable while iterating. Server installs and
`bb plugin build` minify.
- The Tailwind output plus authored CSS run through Tailwind's own
optimizer (`optimize` from `@tailwindcss/node`, the lightningcss pass
the host's Vite build uses); minified in production, pretty in dev, same
browser-target lowering in both.
- `bb.pluginTailwindContent` globs now only select which dependency
files may be scanned; the scan reads their intersection with esbuild's
`metafile.inputs`, so a plugin pays only for the shared components it
bundles. Scan bases are realpath'd because esbuild reports real paths
for workspace links.
- The generated plugin theme marks the host's `@theme inline` bridge as
`inline reference`: inline tokens are substituted into utilities at
compile time, so the `:root { --color-*: var(--*) }` block was never
read by plugin rules. Non-inline tokens still emit.
- Removed `app.tsx` / `bb.app` / react devDeps from the four provider
plugins; updated the provider-icon comment, `docs/api_to_audit.md`, and
the plugin-authoring skill example that pointed at the deleted file.

Built-in bundle bytes (raw / gzip), before -> after:

| plugin | app.js | app.css |
| --- | --- | --- |
| tasks | 2,383,490 / 503,399 -> 1,257,491 / 360,279 | 127,234 / 15,866
-> 51,898 / 8,763 |
| docs | 1,641,918 / 374,940 -> 839,167 / 262,909 | 112,434 / 14,127 ->
30,250 / 5,502 |
| automations | 1,064,406 / 185,248 -> 587,528 / 141,850 | 112,712 /
14,112 -> 51,952 / 8,449 |
| secrets | 644,324 / 100,199 -> 352,915 / 76,467 | 110,067 / 13,891 ->
17,288 / 3,321 |
| provider-* (x4) | ~2-3.6 KB each -> none | ~3-4.3 KB each -> none |

## How you verified

- New tests in `packages/plugin-build/src/build-plugin-app.test.ts`:
minified vs readable artifacts (identifier mangling, license comment
dropped, CSS minified/pretty for both utilities and authored CSS);
dependency scanning through a symlinked package with a negated pattern
(bundled file scanned, glob-only file not, negated file not, plugin's
own dir still scanned whole, `:root` has the default token and not the
bridge). Both fail before the change.
- Updated dependent assertions for minified CSS in `apps/cli`
plugin-build test, `apps/server` plugin-app-bundle test, and
`packages/plugin-registry` vendor test.
- `turbo run typecheck` for @bb/plugin-build, @bb/cli, @bb/server,
@bb/app, @bb/plugin-registry and the four provider plugins: pass. `turbo
run lint --filter=@bb/app`: pass.
- `turbo run test`: @bb/plugin-build full suite (22 passed, 1 skipped);
@bb/cli plugin-build, docs/github official bundle,
packaged-plugin-build, plugin-dev-loop (21 passed); @bb/server
`test/services/plugins` (34 files, 380 passed); @bb/plugin-registry
vendor-all-items; @bb/app provider-icon test.
- Rebuilt all builtins with
`apps/server/scripts/copy-builtin-plugins.ts` before and after for the
byte table above.

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


## Stack context

Layer 16 of 22 in the `bb/mobile-perf/*` stack (bottom → top: quick wins
first, big rocks last).
- Prerequisite (layer below):
`bb/mobile-perf/pierre-pool-and-route-closure` (#1894).
- Next layer: `bb/mobile-perf/plugin-boot-defer` (#1896).
- Audit findings addressed: see title IDs. Review: approved-with-fixes;
1 review fix commit(s).
- Reviewer notes / follow-ups: Minified production plugin bundles ship
without source maps (implementer-acknowledged; dev loop is readable).
Not a blocker. | Authored plugin CSS now passes through lightningcss
(errorRecovery on, warnings printed); invalid authored CSS is dropped at
build time rather than by the browser. Behavioural but | Four touched
files (bb-plugin-authoring SKILL.md, generate-plugin-theme.mjs,
vendor-all-items.test.ts, provider-pi/tsconfig.json) are not
prettier-clean, but they were already not
- Wire/contract: None. No server<->daemon wire, RPC, or session payload
changed; HOST_DAEMON_PROTOCOL_VERSION untouched. Artifact format
(dist/app.js, app.css, app.meta.json, artifactFormatVersion 1)
unchanged; only content minification. Public API:
`buildPluginApp(rootDir, bbVersion, toolchain, options?:
PluginAppBuildOptions)` gained an optional 4th arg (exported type
PluginAppBuildOptions from @bb/plugin-build)

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

---------

Co-authored-by: Claude <[email protected]>
SawyerHood added a commit that referenced this pull request Aug 21, 2026
## What was wrong

Issue #1072 (report: https://get-bb.github.io/reports/issues/1072.html)
tracks heavy packages that sit in the static import closure of the lazy
thread route (`SplitWorkspaceRoute`), so every thread open downloads and
parses them before the timeline paints. Since the report was written,
main already cut three of the five edges it names: `FilePreview ->
@pierre/diffs` and the secondary-panel surfaces (#1894),
`markdown-preview -> rehype-katex` (#1891), and Handlebars (#2080). The
budget check in CI now ratchets that closure.

One edge was still open: `useThreadStorageBrowser.ts` imported
`@pierre/trees/react` statically, and `ThreadDetailView` calls that hook
on every thread page (it has to, so the tree model survives the
Info-tab/file-tab toggle). That put the tree model, its renderer and
preact (~250 KB raw / ~62 KB brotli emitted) in the route closure,
although only the "Thread storage" browser in the Info tab renders a
tree, and the storage file list itself is only fetched once the panel
opens. `node scripts/why-eager.mjs --from=views/SplitWorkspaceRoute.tsx
node_modules/@pierre/trees` on main:

```
0. apps/app/src/views/SplitWorkspaceRoute.tsx
1. apps/app/src/views/thread-detail/SplitThreadArea.tsx
2. apps/app/src/views/thread-detail/ThreadDetailView.tsx
3. apps/app/src/components/secondary-panel/useThreadStorageBrowser.ts
4. node_modules/@pierre/trees/dist/react/index.js
```

## What changed

All in `apps/app`.

- `src/components/secondary-panel/ThreadStorageFileTree.tsx` (new): the
only runtime importer of `@pierre/trees`. Exports
`createThreadStorageTreeModel(onSelectionChange)` (the `new
FileTree(...)` that `useFileTree` wrapped) and the
`ThreadStorageFileTree` render component with the host style that used
to live in `ThreadStorageBrowser.tsx`.
- `useThreadStorageBrowser.ts`: no static tree import. When a thread has
storage files, an effect imports the gate module (through
`createRetryingModuleLoader`, the same helper the pierre worker pool
uses) and builds the model; `model` is `null` until then, the
`resetPaths`/selection sync effects wait for it, and cleanup calls
`model.cleanUp()` and ignores a load that resolves after unmount. A
failed chunk fetch logs a warning and the next mount retries.
- `ThreadStorageBrowser.tsx`: renders the tree through
`LazyThreadStorageFileTree` (new wrapper in
`lazySecondaryPanelComponents.tsx`) and shows the existing "Loading
files..." state while `model` is `null`.
- `bundle-budget.json`: `@pierre/trees` added to the
`SplitWorkspaceRoute` forbidden list and to `onDemandPackages` (gate:
`ThreadStorageFileTree.tsx`, so no chunk outside that gate may reach
it); route budget ratcheted to 10% above the new measurement (2,268,430
raw / 605,332 brotli, from 2,533,484 / 671,561).

Route closure, `node scripts/check-bundle-budget.mjs`: before 2260.4 KB
raw / 599.1 KB brotli, after 2013.9 KB raw / 537.4 KB brotli (-11% raw,
-10% brotli). The tree now ships as `ThreadStorageFileTree-*.js`
(253,881 B raw / 64,341 B brotli) fetched when the storage browser first
has files.

Not in this PR: the composer (`PromptBoxInternal -> tiptap/prosemirror`,
~600 KB raw in the shared `workspace-checkout-display` chunk). It is
visible on every thread page, `PromptBoxInternal.tsx` owns the
`useEditor` instance across 3,600 lines, and a first-focus handoff has
to keep draft restore, autofocus, the mention menu and iOS
keyboard-on-tap working. #1894 deliberately left it allowed in the route
budget for that reason; it needs its own design.

A previous agent's WIP on this branch (a null-rendering "tree model
host" component returned from the hook as a ReactNode) was discarded in
favour of the imperative model factory above.

## How you verified

- New `useThreadStorageBrowser.test.tsx` (real `@pierre/trees` in jsdom,
`vi.mock` factories only record when the library is first evaluated):
- "loads the tree library only once there are files to show" fails on
main's source files with `AssertionError: expected "vi.fn()" to not be
called at all, but actually been called 1 times ...
"@pierre/trees/react"` and passes on this branch.
- "syncs files and selection into the model once it arrives, then
destroys it on unmount": the files and `selectedPath` that arrived
before the chunk are applied to the model; reconciling selection does
not echo through `onSelectPath`; unmount calls `cleanUp()` once.
- `node scripts/check-bundle-budget.mjs` with the new
`bundle-budget.json` against main's build: `@pierre/trees is in the
SplitWorkspaceRoute closure (assets/SplitWorkspaceRoute-9lmZmaba.js). It
must load on demand`, exit 1. After rebuilding on this branch: `Bundle
budget OK` (including the new on-demand gate check).
- `pnpm exec turbo run typecheck --filter=@bb/app --force`, `pnpm exec
turbo run lint --filter=@bb/app --force`, `pnpm exec turbo run build
--filter=@bb/app`: pass. (The first push of this PR had two TS2322
errors in the new test file: `renderHook(..., { initialProps: { files:
undefined } })` inferred the props type as `{ files: undefined }`, so
the later `rerender({ files: [] })` calls did not compile and the CI
bundle-budget step never ran. The test now declares `initialProps` with
an explicit `{ files: readonly WorkspaceFile[] | undefined }` type; the
forced typecheck is clean and the fail-before/pass-after result above
was re-run with the typed test.)
- `pnpm exec turbo run test --filter=@bb/app --force`: all files pass.
- Manual, own dev instance + headless Chrome: opened a codex thread with
two seeded storage files (`docs/notes.md`, `main.ts`); thread painted;
opened the right panel, the "Thread storage" tree rendered `docs` and
`main.ts`; clicking `main.ts` opened the file preview tab; switching
back to Info showed the same tree (model survived the tab toggle).

Fixes #1072

> AGENT GENERATED: by Claude Opus 5




## Independent verification

Round 2, by an independent verifier on a fresh worktree checked out at
`3cf9d8d10` (rebased on `origin/main` `2c0b747a5`; `git merge-base
--is-ancestor origin/main HEAD` true, `mergeable: MERGEABLE`).

Commands run:

- `pnpm install --frozen-lockfile --prefer-offline && pnpm exec turbo
run build` (18/18 tasks).
- `cd apps/app && node scripts/check-bundle-budget.mjs` →
`SplitWorkspaceRoute closure: 2013.9 KB raw / 537.4 KB brotli` (budget
2215.3 / 591.1), `Bundle budget OK.` `node scripts/why-eager.mjs
--from=views/SplitWorkspaceRoute.tsx node_modules/@pierre/trees` → `0
eagerly reachable module(s) ... only reachable behind a dynamic import
(56 modules)`. The tree is emitted as
`ThreadStorageFileTree-BVIqkJpc.js` (253,881 B).
- `pnpm exec turbo run typecheck --filter=@bb/app --force` → `Tasks: 3
successful, 3 total`, no `error TS` (the round-1 TS2322 errors in the
test file are gone).
- `pnpm exec turbo run lint --filter=@bb/app --force` → `Tasks: 1
successful, 1 total`.
- `pnpm exec turbo run test --filter=@bb/app --force` → `Test Files 415
passed (415)`, `Tests 3191 passed | 3 skipped`.

Fail-before / pass-after (`apps/app`, `pnpm exec vitest run
src/components/secondary-panel/useThreadStorageBrowser.test.tsx`):

- With `bundle-budget.json`, `ThreadStorageBrowser.tsx`,
`lazySecondaryPanelComponents.tsx`, `useThreadStorageBrowser.ts` checked
out from `origin/main` and `ThreadStorageFileTree.tsx` removed: `1
failed | 1 passed` — `AssertionError: expected "vi.fn()" to not be
called at all, but actually been called 1 times` with `1st vi.fn() call:
["@pierre/trees/react"]` at `useThreadStorageBrowser.test.tsx:45:38`.
- Restored to the PR tree: `Tests 2 passed (2)`.

Repro on the fixed branch (own dev instance, production `apps/app/dist`
served on a private port with `/api` proxied, headless Chrome,
`performance.getEntriesByType("resource")` with an enlarged buffer;
codex thread `thr_52anzhhcu7` seeded with `docs/notes.md` and `main.ts`
in its thread-storage dir):

- Right panel closed: thread painted; `SplitWorkspaceRoute-BX4iePCW.js`
(267,669 B) and `workspace-checkout-display-BuOjOA0-.js` (1,074,222 B)
fetched at ~290 ms; no `/thread-storage/files` request and no
`ThreadStorageFileTree` chunk at all.
- Right panel open on the Info tab: `/thread-storage/files` at 1087 ms,
then `ThreadStorageFileTree-BVIqkJpc.js` at 1207 ms; the "Thread
storage" tree rendered `docs` and `main.ts`.

CI on `3cf9d8d10`: all checks pass (Checks incl.
`check-bundle-budget.mjs`, Tests app-1/2/3, integration, packages,
server, Package Smoke ubuntu/macos).

Residual risks / notes for the maintainer:

- The composer edge (`PromptBoxInternal -> @tiptap/*` / `prosemirror-*`,
~600 KB raw inside `workspace-checkout-display`) is still a static
import of the thread route; it is named in the issue title and is the
largest remaining item behind "no editor parsing on first paint".
`bundle-budget.json` allows it by design (#1894). If you want #1072 to
keep tracking that edge, change `Fixes #1072` to `Refs #1072` or open a
follow-up issue before merging; otherwise this PR closes it.
- Behavior change is limited to the storage browser: one extra chunk
fetch (and the existing "Loading files..." state) the first time a
thread shows storage files; a failed chunk fetch leaves that state, logs
a `console.warn`, and retries on the next mount. The model is now
created per "files non-empty" span instead of once per
`ThreadDetailView` mount, so it is rebuilt after the file list empties
and refills; `resetPaths` re-applies expansion from the current search
state in both designs, so no visible difference.

> AGENT GENERATED: by Claude Opus 5

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