Skip to content

Lazy-load the Mermaid code block - #4468

Merged
nolannbiron merged 2 commits into
nolann/perf-shiki-splitfrom
nolann/perf-lazy-mermaid
Aug 6, 2026
Merged

Lazy-load the Mermaid code block#4468
nolannbiron merged 2 commits into
nolann/perf-shiki-splitfrom
nolann/perf-lazy-mermaid

Conversation

@nolannbiron

Copy link
Copy Markdown
Member

CodeBlock only renders MermaidCodeBlock when the block's syntax is mermaid, but the import was static. Next inlines every 'use client' module reachable from a route's server graph into that route's client entry (next-flight-client-entry-loader emits import(/* webpackMode: "eager" */ …)), so a runtime conditional in a server component doesn't split anything — the diagram viewer's dependencies shipped on every page that has any code block at all.

Moving the boundary into a 'use client' wrapper puts them in an on-demand chunk instead. ssr: true is kept so real diagram blocks still server-render their skeleton.

Verified on a production build of this branch: @panzoom/panzoom and the Mermaid wrapper no longer appear in the route's entry chunks.

Initial client JS for the docs route:

nolann/perf-shiki-split (base) 1616.3 KB
this branch 1604.2 KB
−12.1 KB

The byte saving is deliberately small — the Mermaid engine itself was already behind import('mermaid'). What changes is that pages with code blocks but no diagram stop loading the viewer's wrapper and its dependencies at all.

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e545766

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
gitbook Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@argos-ci

argos-ci Bot commented Aug 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v2-cloudflare (Inspect) 👍 Approved by Nolann Biron 38 changed, 4 ignored Aug 5, 2026, 2:39 PM
customers-v2-vercel (Inspect) 👍 Approved by Nolann Biron 13 changed, 31 ignored Aug 5, 2026, 2:37 PM
v2-cloudflare (Inspect) 👍 Approved by Nolann Biron 8 changed, 1 ignored Aug 5, 2026, 2:40 PM
v2-vercel (Inspect) 👍 Approved by Nolann Biron 8 changed, 1 ignored Aug 5, 2026, 2:38 PM

@nolannbiron
nolannbiron marked this pull request as ready for review August 5, 2026 14:54
@nolannbiron
nolannbiron merged commit 2ccd43e into main Aug 6, 2026
17 checks passed
@nolannbiron
nolannbiron deleted the nolann/perf-lazy-mermaid branch August 6, 2026 06:59
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.

2 participants