Skip to content

codeblock: replace prism-react-renderer with shiki#18194

Merged
pettinarip merged 3 commits into
devfrom
codeblock-shiki
May 20, 2026
Merged

codeblock: replace prism-react-renderer with shiki#18194
pettinarip merged 3 commits into
devfrom
codeblock-shiki

Conversation

@pettinarip
Copy link
Copy Markdown
Member

@pettinarip pettinarip commented May 14, 2026

Summary

Replaces prism-react-renderer with shiki for code block syntax highlighting. The new Codeblock is an async server component; the client wrapper only owns the collapse + copy controls.

Why

  • Correctness across the languages we actually use. Our content has 13k+ Solidity blocks, 4.9k Python, 2.1k bash/shell, 1k Rust, plus JS/TS/TSX/JSX. prism-react-renderer (and JS-only alternatives like sugar-high) mis-tokenise everything outside the JS family on the tutorials and docs pages — exactly where highlighting matters most. Shiki ships 692 grammars and handles all of them.
  • Zero client JS. Highlighting runs server-side; the resulting HTML string is handed to a tiny "use client" wrapper via dangerouslySetInnerHTML. Grammars/themes never cross the RSC boundary, so the client bundle does not grow.
  • Build-time cost, not request-time. Cost is ~10–16 ms per block on cold call, amortised across statically-generated tutorial/docs routes — well under the noise floor next to MDX compilation.
  • Theme switching with no re-highlight. Shiki emits inline --shiki-light / --shiki-dark CSS variables; the dark theme is selected purely via the .dark ancestor.

Changes

  • New src/components/Codeblock/ (server Codeblock.tsx + client CodeblockClient.tsx) replaces the old single-file src/components/Codeblock.tsx.
  • src/lib/shiki.ts — singleton highlighter with a fixed lang/theme allowlist (one-light + one-dark-pro) to avoid lazy-import latency on cold starts.
  • src/styles/codeblock.css — token styles + dark-mode variable swap, imported once from global.css.

Test plan

  • Tutorials render correctly in light + dark mode (/developers/tutorials/uniswap-v2-annotated-code — 149 blocks, good stress test)
  • Solidity, Python, bash, Rust blocks tokenise (not just JS)
  • Copy button + collapse still work
  • No shiki / codeToHtml / @shikijs symbols leak into .next/static/chunks/*.js

@pettinarip pettinarip requested a review from wackerow as a code owner May 14, 2026 12:57
@netlify
Copy link
Copy Markdown

netlify Bot commented May 14, 2026

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit d30b0f1
🔍 Latest deploy log https://app.netlify.com/projects/ethereumorg/deploys/6a0dc6d395c64c00082b7a13
😎 Deploy Preview https://deploy-preview-18194.ethereum.it
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 67 (🟢 up 3 from production)
Accessibility: 96 (no change from production)
Best Practices: 100 (🟢 up 1 from production)
SEO: 98 (🔴 down 1 from production)
PWA: 59 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added dependencies 📦 Changes related to project dependencies tooling 🔧 Changes related to tooling of the project labels May 14, 2026
Copy link
Copy Markdown
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple non-blocking comments, but this looks great to me @pettinarip, thanks! This paired with #18195 will be a nice polish to all the codeblocks.

Comment thread src/components/Codeblock/Codeblock.tsx Outdated
Comment thread src/components/Codeblock/index.tsx
Address PR review feedback (#18194)

- Remove COPY_WIDGET_LANGS allowlist so the copy button shows for every
  non-homepage codeblock instead of only js/json/python/solidity.
- Move Codeblock.tsx into index.tsx and drop the index.ts re-exporter.
# Conflicts:
#	src/components/Codeblock/index.tsx
@pettinarip pettinarip merged commit 1ccabfa into dev May 20, 2026
14 checks passed
@pettinarip pettinarip deleted the codeblock-shiki branch May 20, 2026 14:58
@claude claude Bot mentioned this pull request May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies 📦 Changes related to project dependencies tooling 🔧 Changes related to tooling of the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants