Skip to content

Thread route still statically imports the 2.15 MB shared chunk (+ katex): FilePreview → @pierre/diffs, markdown-preview → rehype-katex, PromptBox → tiptap should be lazy #1072

Closed

Description

@toasterman234

Problem

After #1070 removed Shiki from the critical path, workspace-checkout-display is still 1.7MB and preloaded via <link rel="modulepreload"> in the HTML shell. This means every thread page load pulls in the full code editor before rendering.

What's in it

workspace-checkout-display: 1.7MB
  ├── Monaco/Eddie editor (~800KB+)
  ├── Cytoscape (graph visualization) (~425KB)
  ├── Katex (math rendering) (~253KB)
  └── 30+ utility chunks bundled together

Import chain

index.js eagerly includes modules that import formatWorkspaceCheckoutDisplay from @/lib/workspace-checkout-display. Vite sees this as a static dependency and bundles the entire editor tree into the preload set.

Files that pull it in:

  • ThreadDetailView.tsx — imports formatWorkspaceCheckoutDisplay
  • ThreadMetadataContent.tsx — imports formatWorkspaceCheckoutDisplay
  • PluginThreadChat.tsx — imports formatWorkspaceCheckoutDisplay
  • ThreadEnvironmentSummary.tsx — imports the type

Fix

  1. Split @/lib/workspace-checkout-display into a light type-only module and a heavy implementation module. The type is used everywhere; the implementation (which pulls in the editor) should be lazy-loaded.

  2. Lazy-load the actual editor — ThreadDetailView, ThreadMetadataContent, and PluginThreadChat only need formatWorkspaceCheckoutDisplay for rendering a small environment label. That function shouldn't pull in the full editor.

  3. Audit why Cytoscape and Katex are bundled here — they should be in their own lazy chunks.

Target

  • workspace-checkout-display under 500KB (from current 1.7MB)
  • No editor code in HTML modulepreload
  • Thread view first paint: no editor parsing on critical path

Related: #1063, #1070

Activity

  1. SawyerHood commented on Aug 7, 2026

    @SawyerHood
    Collaborator

    Yeah agree we should move this off of the critical path.

  2. added theissue type on Aug 7, 2026
  3. self-assigned this
    on Aug 8, 2026
  4. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1072.html

    • Verdict: PARTIALLY REPRODUCED · root-cause confidence: high
    • Root cause (short): The HTML-shell preload of the 2.4MB shared chunk was fixed by Cut the web app boot payload by 60% #1071 (eager edge was App.tsx→usePluginFrontendBoot→plugin-frontend.ts, not the 85-line workspace-checkout-display module that merely lends the chunk its name); but the same 2.15MB chunk plus katex is still a static import of the lazy thread route (SplitWorkspaceRoute) via FilePreview→@pierre/diffs, markdown-preview→rehype-katex, PromptBoxInternal→tiptap, useThreadStorageBrowser→@pierre/trees and thread-operation-prompts→handlebars, so a thread page still parses ~3.3MB of editor/diff/tree/math/template code before first paint.
    • Proposed fix: Retitle the issue (the module-split idea is a no-op; Monaco/Cytoscape claims are wrong). Then in apps/app cut the static edges that put heavy packages on the thread route: React.lazy the Pierre file viewer inside secondary-panel/FilePreview.tsx; make ui/markdown-preview.tsx load rehype-katex + katex CSS lazily only when remark-math finds a math node (same pattern as MarkdownMermaidDiagram); move @pierre/trees into a lazily loaded storage-browser tab; dynamic-import @bb/templates (Handlebars) inside the git-action handler or precompile the templates; lazy-load PromptBoxInternal (Tiptap/ProseMir…
    • Caveats: Revision: the browser repro was made runnable by others (new browser-thread-page-loads.sh wrapper takes project/thread/port; dev-browser's QuickJS sandbox has no process.env so a placeholder+wrapper is used; waitUntil load + 6s instead of networkidle) and re-run end to end on a fresh dev instance (server :24027, proj_6b34bf5w5e / thr_v52fuawjmu); the JSON artifact and screenshot were regenerated a…

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at 16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by Claude Opus 5

  5. added
    partial-repro
    on Aug 18, 2026
  6. changed the title [-]workspace-checkout-display (1.7MB) bundles Monaco/Eddie editor eagerly — should be lazy[/-] [+]Thread route still statically imports the 2.15 MB shared chunk (+ katex): FilePreview → @pierre/diffs, markdown-preview → rehype-katex, PromptBox → tiptap should be lazy[/+] on Aug 18, 2026
  7. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Retitled to match what reproduced (https://get-bb.github.io/reports/issues/1072.html). Refuted: workspace-checkout-display is an 85-line module that merely lends the chunk its name; the eager HTML-shell preload edge (App.tsx → usePluginFrontendBoot → plugin-frontend.ts) was fixed by #1071, and the Monaco/Cytoscape attributions were wrong. What is still true: the same 2.15 MB chunk plus katex CSS is a static import of the lazy thread route (SplitWorkspaceRoute) through FilePreview → @pierre/diffs, ui/markdown-preview → rehype-katex, and PromptBoxInternal → tiptap. Making those three edges React.lazy/dynamic is the remaining work.

    AGENT GENERATED: by Claude Opus 5

  8. added
    confirmed-repro
    and removed
    partial-repro
    on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-reproperf

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions