Skip to content

feat(ui): add comark-ui/shiki, a highlighter that loads each grammar on first use - #423

Merged
vite-hub[bot] merged 3 commits into
mainfrom
feat/lazy-shiki
Nov 13, 2026
Merged

vite-hub[bot] merged 3 commits into
mainfrom
feat/lazy-shiki

Conversation

@onmax

@onmax onmax commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Drop and ViteHub each build the same Shiki before they pass it to comark-ui's shiki option: the JavaScript regex engine, an empty createHighlighterCore, and a table of dynamic imports that loads a grammar the first time a fence asks for it. Drop's is shared/highlighter.ts, about 130 lines. ViteHub has two in packages/ui, composables/highlighted-code.ts and playground/highlight.ts.

This adds createLazyHighlighter({ languages, aliases, themes }) from comark-ui/shiki. It returns { highlighter, themes }, which the preset's shiki option takes as is, plus language(info) and languages for a host that needs to know what it highlights, such as a language picker.

import { createLazyHighlighter } from "comark-ui/shiki";

comarkUi({
  shiki: createLazyHighlighter({
    languages: { typescript: () => import("@shikijs/langs/typescript") },
    aliases: { ts: "typescript" },
    themes: {
      light: () => import("@shikijs/themes/github-light"),
      dark: () => import("@shikijs/themes/github-dark"),
    },
  }),
});
  • A grammar loads once, even when several documents ask for it at the same moment. A fence in a language that isn't listed gets undefined before anything loads.
  • A grammar that fails to load leaves its block plain and loads again on the next call, like ViteHub's copy.
  • The themes load under the names light and dark, so themes is known before either one loads.
  • Shiki only knows a grammar's own aliases once it has loaded, so the host lists the names its fences use in aliases. They also go to Shiki's langAlias, so codeToTokens reads a name like deno that the grammar doesn't list.

shiki becomes an optional peer dependency of comark-ui (^3.0.0 || ^4.0.0), and the preset still bundles no grammars. The docs are in Getting started's Code highlighting section, the package README, and the comark-ui skill's reference. Limits still work by spreading it: shiki: { ...highlighter, maxSource: 200_000 }.

packages/ui/test/shiki.test.ts renders through the HTML preset. It checks colors with both themes, one load per grammar across concurrent renders, an alias the grammar doesn't know, an unlisted language, and a failed load that loads again. It's a new export, so there's nothing on main for it to fail against. I ran the ui, skills and workspace tests, pnpm typecheck, the comark-ui build with publint, its Vite Doctor, and pnpm run lint:docs. I didn't run the e2e suite, and I only tried Shiki 4.5.0, not 3.x.

…r on first use

`createLazyHighlighter({ languages, aliases, themes })` takes Shiki's grammars and themes as dynamic imports and
returns the preset's `shiki` option. It runs on the JavaScript regex engine, loads each grammar once the first time a
fence asks for it, and loads a failed grammar again on the next call. Drop and ViteHub each carry a copy of this.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T17:46:13.673574Z
We couldn’t complete this review. Comment @codex review to try again.
eaeb0de PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vite-hub

vite-hub Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Session Status Started Duration
Pending Completed 2026-11-13T20:50:35.041Z 11s

Latest result

Merged 45deb47 directly: required checks passed and review threads were resolved.

Final answers

Session

Merged 45deb47 directly: required checks passed and review threads were resolved.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

Session

No actionable findings remain; prior fixes are verified and all review threads are resolved. Four focused tests and lint passed. The failing Doctor check reproduces with the same five warnings on exact base f69708d, so no repair push is warranted. Build and E2E checks passed. Ready from this repair pass; required GitHub checks remain authoritative.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important

An undefined optional dark theme and uppercase fence names silently disable highlighting. The documented pnpm setup also leaves the examples’ grammar and theme imports unresolved.

Reviewed changes Reviewed the new lazy Shiki helper, its integration with the preset, the published entry point, and the accompanying tests and documentation.

  • Lazy initialization: Creates one JavaScript-engine highlighter and coalesces grammar loads, with retries after initialization or grammar-loading failures.
  • Preset integration: Exposes theme names, configured languages, and alias resolution alongside the preset-compatible highlighter callback.
  • Packaging: Adds comark-ui/shiki and an optional Shiki 3/4 peer without importing the helper into the existing preset entries.
  • Tests and guidance: Adds HTML-rendering tests and usage examples in Getting started, the README, and the agent reference.

Validation passed: direct workspace builds with publint, typechecking, 447 focused tests with one skipped, and an isolated Shiki 3.0.0 smoke check. Additional public-API reproductions confirmed the findings below.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol(xhigh) | 𝕏

Comment thread packages/ui/src/highlighter.ts Resolved
Comment thread packages/ui/src/highlighter.ts Resolved
Comment thread docs/pages/getting-started.md Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No new issues found; no P0 or P1 findings remain.

Reviewed changes Reviewed e189923, the fixes added since the previous Pullfrog review.

  • Skipped absent theme loaders: Preserved light-only highlighting when dark is explicitly undefined.
  • Normalized tokenization inputs: Made uppercase fence names and aliases use the same canonical grammar as the resolver.
  • Corrected installation examples: Replaced transitive-package imports with public shiki language and theme subpaths.
  • Extended HTML regressions: Added coverage for uppercase fences and explicitly absent dark themes.

Validation passed: 448 focused tests with one skipped, workspace typechecking, and direct comark-ui and linter builds with publint. Built-export smoke checks also passed for cold concurrent highlighting, single grammar/theme loading, and theme-load retry. The aggregate pnpm build exceeded the command’s 120-second timeout; full-workspace build completion and E2E were not verified in this run.

Pullfrog  | View workflow run | Using gpt-6.1-sol(xhigh) | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark-annotate

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-annotate@423

comark-badge

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-badge@423

comark-cards

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-cards@423

comark-carousel

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-carousel@423

comark-cast

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-cast@423

comark-charts

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-charts@423

comark-chat

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-chat@423

comark-chips

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-chips@423

comark-cjk

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-cjk@423

comark-code

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-code@423

comark-code-notes

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-code-notes@423

comark-colors

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-colors@423

comark-comments

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-comments@423

comark-critic

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-critic@423

comark-deflist

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-deflist@423

comark-details

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-details@423

comark-diagrams

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-diagrams@423

comark-diff

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-diff@423

comark-embed

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-embed@423

comark-fields

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-fields@423

comark-figure

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-figure@423

comark-file-tree

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-file-tree@423

comark-footnotes

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-footnotes@423

comark-git-graph

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-git-graph@423

comark-github

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-github@423

comark-icon

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-icon@423

comark-include

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-include@423

comark-keys

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-keys@423

comark-links

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-links@423

comark-linter

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-linter@423

comark-magic-move

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-magic-move@423

comark-mark

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-mark@423

markdown-it-to-comark

pnpm add https://pkg.pr.new/onmax/comark-ui/markdown-it-to-comark@423

marked-to-comark

pnpm add https://pkg.pr.new/onmax/comark-ui/marked-to-comark@423

comark-mathml

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-mathml@423

comark-media

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-media@423

comark-metrics

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-metrics@423

migrate-to-comark

pnpm add https://pkg.pr.new/onmax/comark-ui/migrate-to-comark@423

comark-outline

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-outline@423

comark-properties

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-properties@423

comark-qr

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-qr@423

comark-quiz

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-quiz@423

comark-reading-time

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-reading-time@423

remark-to-comark

pnpm add https://pkg.pr.new/onmax/comark-ui/remark-to-comark@423

comark-sources

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-sources@423

comark-steps

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-steps@423

comark-table

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-table@423

comark-tabs

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-tabs@423

comark-tests

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-tests@423

comark-time

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-time@423

comark-ui

pnpm add https://pkg.pr.new/onmax/comark-ui@423

comark-xref

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-xref@423

comark-zoom

pnpm add https://pkg.pr.new/onmax/comark-ui/comark-zoom@423

commit: 45deb47

@vite-hub
vite-hub Bot merged commit 85434db into main Nov 13, 2026
7 checks passed
@vite-hub
vite-hub Bot deleted the feat/lazy-shiki branch November 13, 2026 20:50
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026
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.

1 participant