fix(app): move markdown parsing to worker - #40356
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR moves Markdown projection/parsing (including KaTeX rendering and Shiki highlighting) off the renderer thread into the existing session Markdown worker, while upgrading marked to v18 and removing now-unneeded workarounds/dependencies to reduce bundle size and avoid UI freezes.
Changes:
- Upgrade
markedto 18.0.7, remove the code-span workaround andmarked-katex-extensionusage, and centralize markdown parsing in a sharedcreateMarkdownParser. - Extend the session Markdown worker to support projection + full markdown parsing in addition to streaming code highlighting, and update renderer integration to call the worker.
- Extract the OpenCode Shiki theme into a dedicated module and remove the app-level
MarkedProviderdependency.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui/src/context/marked.tsx | Refactors Marked context to use shared parser + extracted theme and removes the previous inline parsing/highlighting logic. |
| packages/ui/src/context/marked-theme.tsx | New extracted OpenCode Shiki theme definition. |
| packages/ui/src/context/marked-regression.test.ts | Updates regression test to rely on marked v18 behavior (removes workaround extension). |
| packages/ui/src/context/marked-parser.tsx | New shared markdown parser factory (Marked + KaTeX + marked-shiki). |
| packages/ui/src/context/marked-parser.test.ts | New unit tests covering link rendering, math rendering, and configured highlighter behavior. |
| packages/ui/src/context/marked-code-span.ts | Removes the legacy code-span boundary workaround module. |
| packages/ui/package.json | Drops marked-katex-extension dependency from UI package. |
| packages/session-ui/src/components/markdown.worker.ts | Adds “parse” + “project” capabilities to the worker and wires in the shared markdown parser + theme. |
| packages/session-ui/src/components/markdown.tsx | Switches rendering to worker-backed projection + parsing, updates code highlighting integration, and adds projection disposal. |
| packages/session-ui/src/components/markdown-worker.ts | Updates worker bootstrap and adds parse/project request handling + lifecycle management. |
| packages/session-ui/src/components/markdown-worker-protocol.ts | Extends protocol for parse/project responses and includes language in highlight responses/state. |
| packages/session-ui/src/components/markdown-worker-protocol.test.ts | Updates protocol tests for new language field and response shapes. |
| packages/session-ui/src/components/markdown-stream.ts | Moves canReusePendingBlock out to a new module. |
| packages/session-ui/src/components/markdown-stream.test.ts | Updates imports for the extracted canReusePendingBlock. |
| packages/session-ui/src/components/markdown-projection.ts | New module containing canReusePendingBlock logic. |
| packages/session-ui/src/components/markdown-preload.test.ts | Removes prior markdown preload cache test. |
| packages/session-ui/src/components/markdown-cache.tsx | Changes preload to worker-based parsing and simplifies caching to a single full-block entry. |
| packages/session-ui/package.json | Removes KaTeX/Marked parsing deps from session-ui (now pulled via UI worker bundle). |
| packages/app/src/pages/home/home-sessions-controller.tsx | Updates home preloading to the new preloadMarkdown signature (no provider parser needed). |
| packages/app/src/app.tsx | Removes MarkedProvider from app provider tree. |
| package.json | Bumps root catalog marked version to 18.0.7. |
| bun.lock | Lockfile updates reflecting dependency removals and marked version bump. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+360
to
+362
| function pendingProjection(text: string): Projection { | ||
| return { text, blocks: text ? [{ raw: text, src: text, mode: "live" }] : [] } | ||
| } |
Comment on lines
+55
to
+68
| export async function preloadMarkdown(text: string, cacheKey: string) { | ||
| const key = `${cacheKey}:0:full` | ||
| const cached = getCachedMarkdown(key) | ||
| if (cached?.raw === text) { | ||
| touchCachedMarkdown(key, cached) | ||
| return | ||
| } | ||
| const hash = checksum(text) | ||
| if (!hash) return | ||
| touchCachedMarkdown(key, { | ||
| raw: text, | ||
| hash, | ||
| html: sanitizeMarkdown(await parseMarkdown(text)), | ||
| }) |
Hona
enabled auto-merge (squash)
August 4, 2026 04:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs #40347
Testing