perf(markdown): move code highlighting off the main thread into a Shiki worker

Tokenize closed code blocks in a dedicated Shiki Web Worker instead of calling
the shared highlighter synchronously on the UI thread. This removes the
one-shot main-thread highlight stall when a code fence closes on a large block.

Streaming behavior is unchanged: the open (streaming) fence still renders as
plain text and is highlighted once on close. On any worker failure the block
keeps its escaped plain code — highlighting never falls back onto the main
thread.

- Add markdownShikiThemeDefinition (dependency-free CSS-variable theme) so the
  worker can use the theme without pulling in @pierre/diffs / React.
- Add markdown-worker-protocol, markdown-shiki.worker, and the main-thread
  markdown-worker client.
- Route highlightCodeBlocks through the worker; keep the size/VSCode line guard
  and mermaid skip on the main thread.
- Add shiki as a direct dependency (was transitive via @pierre/diffs).
This commit is contained in:
Bohdan Triapitsyn
2026-06-16 01:07:43 +03:00
parent 9ea557d23e
commit 464c4ac0ca
8 changed files with 249 additions and 131 deletions
+1
View File
@@ -73,6 +73,7 @@
"rehype-katex": "^7.0.1",
"remark-math": "^6.0.0",
"remend": "^1.2.1",
"shiki": "^3.23.0",
"simple-git": "^3.28.0",
"sonner": "^2.0.7",
"strip-json-comments": "^5.0.3",