Repository navigation
🤖 perf: lazy-load Mermaid diagrams - #6037
Merged
Merged
Conversation
…frame The new Mermaid test fails until the markdown renderer lazy-loads Mermaid (Refs #5971). Signed-off-by: Thomas Kosiewski <tk@coder.com>
MarkdownComponents and ArtifactViewer load Mermaid with React.lazy inside LazyFeature, so the mermaid package leaves the first load (Refs #5971). The fallback MermaidPendingFrame shares Mermaid's frame and pending styles, so the box does not shift when the chunk arrives. Signed-off-by: Thomas Kosiewski <tk@coder.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
Dogfood evidence from remote UAT on
Generated with |
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.






Summary
Mermaid now loads only when a message or artifact contains a diagram (T3, Refs #5971). The
mermaidcore leaves the first load, so first-load JS drops by 470.6 KiB raw / 108.9 KiB br. While the chunk loads, a shared pending frame shows. It is the same frame Mermaid uses for its own pending state, so nothing shifts when the diagram arrives.Background
Mermaid.tsximportsmermaidand callsmermaid.initializeat module top level.MarkdownComponents.tsxandArtifactViewer.tsximported it statically, so the mermaid core sat in the main chunk on every page load, even though diagrams are rare. The diagram-type chunks were already lazy.Implementation
MermaidPendingFrame.tsx: an eager module with nomermaidimport. It holds the frame, container and pending styles and the "Rendering diagram..." text.Mermaid.tsxnow uses these same style objects for its own pending state instead of inline copies. Its effects, debounce, render and sanitization are unchanged.MarkdownComponents.tsxandArtifactViewer.tsxeach declare a module-top-levelReact.lazyforMermaidand wrap it in<LazyFeature name="Diagram" fallback={<MermaidPendingFrame />}>.mermaid.initializestill runs when the chunk loads, before the first render.LazyFeatureis an ErrorBoundary around Suspense.node_modules/mermaid/is onFIRST_LOAD_FORBIDDEN_SOURCES. Commit 1 adds it with a test that fails on main: on main, 3 zoom buttons render synchronously where 0 are expected.Validation
make first-load-js, KiB). Both sides were cleanmake buildruns with Bun 1.3.12. Base is the merge-base9c1d222f47:mermaidis now only inMermaid-*.js. The plan predicted 7,119 / 1,494 KiB.xum serveron 127.0.0.1, first-run page and seeded workspace page). Both pages request the same JS files as base before LCP, and no new chunk at all. The text and the LCP element are the same as base.xum:app-shell-ready: base 842.1 ms, head 811.0 ms.getBoundingClientRect): head: lazy fallback 714×332 px at top 200.7, Mermaid's own pending state 714×332 at 200.7, rendered SVG 714×332 at 200.7. Base: pending 714×332 at 200.7, SVG 714×332 at 200.7. No shift.XUM_MOCK_AI=1, a message with a mermaid block streams back. The diagram renders in both the user message and the reply, and the chunk is fetched only at the first diagram..mmdartifact renders in the Artifacts tab.make check-react-compilerstill prints23/24 hot components compile (1 known skipped)(MarkdownCore is on the hot list).make static-checkpasses.bun test src/browser/features/Messages/ src/browser/features/RightSidebar/ArtifactsTab/ src/browser/components/LazyFeature/ ./scripts/perf/gives 666 pass, 0 fail, including the markdown, streaming and Mermaid tests. Fulltests/uigives 357 passed, 3 failed. The 3 failures arecreationGoalFormalRepro(2) andnameGeneration(1), which also fail on main (tests: 3 tests/ui tests fail on main (creationGoalFormalRepro, nameGeneration) #6016).Risks
Low.
Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:high