improvement(chat): code-split resource preview panel out of initial /chat bundle#5331
Conversation
…chat bundle Lazy-load the MothershipView resource-preview panel (file-viewer, rich-markdown, CSV/PDF stack) via React.lazy + local Suspense so it is not in the initial /chat bundle; it only renders once a chat has messages. Remove its now-dead barrel re-export so the split takes effect (this app has no sideEffects:false, so a leftover barrel edge drags the heavy module back into the initial chunk). Also a small behavior-preserving perf pass on the input surface: - toSorted (non-mutating) instead of spread+sort in use-skill-auto-mention - Map first-match lookup instead of .find()-in-loop in prompt-editor Document the code-split/barrel gotcha in .claude/rules/sim-imports.md.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview Removes Micro perf in Reviewed by Cursor Bugbot for commit 5c0f786. Configure here. |
Greptile SummaryThis PR code-splits the
Confidence Score: 5/5Safe to merge — the change is purely additive in bundle terms, all DOM ref usages remain guarded, and the barrel removal has no other consumers. The lazy split is implemented correctly: the deep import path bypasses the barrel, the Suspense boundary is scoped locally so there is no page-level flash, and every access to mothershipRef.current in use-mothership-resize.ts already carries a null guard (if (!el) return / optional chaining). The barrel re-export removal was verified to have no remaining consumers. The Map optimization in prompt-editor preserves first-match semantics. No regressions were introduced. No files require special attention. Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Browser
participant Next.js
participant InitialChunk as /chat initial chunk
participant LazyChunk as MothershipView chunk (lazy)
Browser->>Next.js: navigate to /chat
Next.js->>InitialChunk: load (home.tsx, MothershipChat, UserInput, etc.)
Note over InitialChunk: MothershipView NOT included
InitialChunk-->>Browser: render landing view (no messages)
Browser->>Next.js: user sends first message
Next.js-->>Browser: "hasMessages = true, non-early-return branch"
Browser->>LazyChunk: React.lazy triggers fetch
LazyChunk-->>Browser: MothershipView chunk loaded
Note over Browser: Suspense fallback=null during load (no flash)
Browser-->>Browser: MothershipView mounts with ref forwarded
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Browser
participant Next.js
participant InitialChunk as /chat initial chunk
participant LazyChunk as MothershipView chunk (lazy)
Browser->>Next.js: navigate to /chat
Next.js->>InitialChunk: load (home.tsx, MothershipChat, UserInput, etc.)
Note over InitialChunk: MothershipView NOT included
InitialChunk-->>Browser: render landing view (no messages)
Browser->>Next.js: user sends first message
Next.js-->>Browser: "hasMessages = true, non-early-return branch"
Browser->>LazyChunk: React.lazy triggers fetch
LazyChunk-->>Browser: MothershipView chunk loaded
Note over Browser: Suspense fallback=null during load (no flash)
Browser-->>Browser: MothershipView mounts with ref forwarded
Reviews (2): Last reviewed commit: "fix(chat): drop unsafe toSorted, keep co..." | Re-trigger Greptile |
toSorted (ES2023) is not polyfilled by SWC and crashes iOS15/Safari<16 in client bundles, so revert use-skill-auto-mention to the non-mutating [...arr].sort() it had. The code-split of MothershipView and the first-match Map lookup in prompt-editor are unaffected. Tighten the sim-imports code-split note to state webpack *can* retain the barrel edge (removing the dead re-export is the guaranteed fix).
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5c0f786. Configure here.
Summary
MothershipViewresource-preview panel (file-viewer, rich-markdown, CSV/PDF stack) out of the initial/chatbundle viaReact.lazy+ a local<Suspense>. It only renders once a chat has messages, so it no longer ships on every navigation to/chat.MothershipViewso the split actually takes effect — this app has no"sideEffects": false, so a leftover barrel edge would drag the heavy module back into the initial chunk.toSorted(non-mutating) instead of spread+sort inuse-skill-auto-mention; aMapfirst-match lookup instead of.find()-in-loop inprompt-editor..claude/rules/sim-imports.md.Type of Change
Testing
tsc0 errors,biomecleanuser-inputtests 14/14 passlazy(memo(forwardRef))reaches the DOM node (resize keeps working), the fallback window is null-guarded inuse-mothership-resize, Suspense is scoped locally (no page-level fallback flash), and the two micro-fixes are behaviorally identical (first-match preserved, non-mutating sort)Checklist