Skip to content

Conversation

dav-is
Copy link
Member

@dav-is dav-is commented Jun 30, 2025

Adds an isomorphic (server and client loading/parsing) and build-optimizable (via a loader) code highlighting component.

Notable Features

  • allows deferring highlighting to various points: init (no defer), stream, hydration, and idle
  • Supports variants and transforms. Variants are manual, transforms happen at build time. Supports TS to JS transforms automatically without the need for a .js file in the repo.
  • Supports MDX or JSX (TSX) usage
  • Supports webpack and turbopack.
  • Supports both the app and pages router in Next.js (no hard dependency on server components like other code highlighters)

Adds 1186 unit tests, covering 70% of statements, 85% of branches, runs in 4 seconds on my machine

Note

The docs are added in a separate PR: #431

Install instructions with variants (remembers preference in local storage)

image

A demo of a codeblock

Screenshot From 2025-07-21 18-10-10

A demo within a demo

Screenshot From 2025-07-21 18-10-29

A demo of a demo with multiple variants

image

Linking to Demo Title Consistent with File Linking

Note

See the address bar

Screenshot From 2025-07-29 00-39-09 Screenshot From 2025-07-29 00-39-20

Read the docs for this component

Precompute Loader Docs

Read the rest of the added docs

Notes

We use ESM only packages for some things (https://www.npmjs.com/package/unified, https://www.npmjs.com/package/jsondiffpatch, etc) so CJS publishing is disabled (at least for now)

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 1, 2025
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Jul 2, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 11, 2025
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Agree to have this merged and iterate. It is already been dogfooded by the Joy UI team internally. Next steps:

  • update Joy UI to use the latest version of the feature & validate that everything works as expected
  • update Base UI's branch to use the new version and check if there are any more regressions before we put it in production.

Very big effort, kudos for the patience :)

@oliviertassinari oliviertassinari temporarily deployed to davis/add-code-highlighter-loader - mui-tools-public PR #379 September 29, 2025 17:17 — with Render Destroyed
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 29, 2025
@dav-is dav-is merged commit b59e262 into master Sep 30, 2025
9 checks passed
@dav-is dav-is deleted the davis/add-code-highlighter-loader branch September 30, 2025 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation. scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs-infra] Unified demo package
7 participants