Repository navigation
refactor(web): render code surfaces through stream-diffs - #1833
Open
Simon-He95 wants to merge 1 commit into
Open
Simon-He95 wants to merge 1 commit into
Simon-He95 wants to merge 1 commit into
Conversation
Replace the two hand-maintained highlighters with one runtime. - Code fences and tool diffs: drop the Shiki `useShikiHighlighter` kernel and the hand-built diff grid; markstream's `CodeBlockNode` (stream-diffs) renders them, inside the existing design-system `CodePanel` frame. - Editors: replace `monaco-editor`/`stream-monaco` with `stream-diffs` surfaces (`code-surface/CodeEditor`, `CodeDiff`, `CodeSurface`, `PatchSurface`), so the file editor, Compare view, asset viewer, JSON dialogs and appearance previews share one runtime. - Keep behaviour: external reloads win over drafts (no retained edit state), focus survives surface rebuilds, light/dark switches update in place, and the card/editor plane and code typography still come from design-system tokens. - Remove the dead Monaco bridge, minimap theming, `getLanguageByFilename`, and the `.typography-code-preview`/`.shiki-preview` styles; move the pure unified-diff helpers to `utils/unified-diff.ts` with their tests. Requires markstream-vue 2.0.32 (code-block editing/stream-diffs handoff) and stream-diffs 0.0.5.
Simon-He95
marked this pull request as draft
November 24, 2026 08:11
Simon-He95
marked this pull request as ready for review
November 24, 2026 09:10
This branch has not been deployed
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.
Author
Type
Summary
The web app carried two hand-maintained highlighter stacks: a Shiki kernel (
useShikiHighlighter, a custom unified-diff row grid) for chat/tool output, andmonaco-editor+stream-monacofor the file editor, Compare view, asset viewer, JSON dialogs and appearance previews. Both are now rendered bystream-diffs.What changed:
CodeBlockNodefrommarkstream-vuerenders fences (streaming handoff and ```diff fences included) throughstream-diffs. The design-system `CodePanel` frame stays — it is the app's own DIY styling (menu-shell radius, card fill, edge rule, copy button), so it was kept and the inner highlight kernel was replaced.apps/web/src/components/code-surface/*wrappers (CodeEditor,CodeDiff,CodeSurface,PatchSurface) replacemonaco-editor/diff.vue,monaco-editor/index.vue,minimap-theme.tsandlazy.ts. The file editor, Compare view, asset viewer, bot-settings JSON dialogs and the two appearance previews all use them.editStateKey, so@pierre/diffskeeps no retained draft),focus()flushes a queued rebuild before focusing, light/dark switches callsetThemeType()and keep the edit session, card/editor plane and code typography still come from design-system tokens.getLanguageByFilename, the dead*** Begin Patchhighlight path, and the.typography-code-preview/.shiki-previewstyles. Pure unified-diff helpers moved toutils/unified-diff.tswith their tests.markstream-vue2.0.26 → 2.0.32,stream-diffs0.0.5 added,monaco-editor,stream-monacoand the unused@shikijs/transformersremoved inapps/webandapps/desktop; both Vite configs pre-bundlestream-diffs+shikiinstead of Monaco.Related Issues
None.
Decision this PR asks for: keep Monaco, or move to stream-diffs?
This is a capability swap, not a drop-in reimplementation, and part of what it removes was built deliberately in this repo. If any item below is a must-have, the correct outcome is to close this PR —
mainalready has the Monaco implementation and nothing there needs to change.Removed on purpose (previously built here)
--surface-editorplane by re-registering themesapps/web/src/components/monaco-editor/minimap-theme.ts(98 lines), added by @qqqqqf-q in #1788, with the minimap behaviour tuned further in #1809@pierre/diffsrenders no minimap (the onlyminimapstrings in its dist are Monaco theme colour keys, no minimap code), so this is a capability loss, not a new implementation of the same thingstickyScrolland the Markdown headingDocumentSymbolprovider written to feed itregisterMarkdownHeadingSymbolsinmonaco-editor/index.vue, added by @qqqqqf-q in #624formatOnPaste/formatOnTypeJSON.parsevalidation and the explicit Format button remainFile/FileDiffrender every lineWhat it buys
Measured on this branch:
monaco-editor/*files are replaced by 8 files / 779 lines underapps/web/src/components/code-surface/.monaco-editor,stream-monacoand@shikijs/transformersare removed fromapps/webandapps/desktop;pnpm --filter @memohai/web buildleaves nomonacoreference indist/assets.Not claimed: this is not a blanket performance win. The editor and Compare surfaces are not virtualized, so very large files are expected to be slower than Monaco. That was not measured.
Behaviour differences from Monaco
main(Monaco)JSON.parsevalidation + explicit Format onlyreadonlychange (the surface is rebuilt)difffences, colours after the block settlesgetLanguageByFilenamemapIf you want the minimap, sticky scroll, Monaco diagnostics or virtualized large-file editing, close this PR; nothing on
mainneeds to change. A smaller middle path exists but is out of scope here: adopt stream-diffs only for chat fences and tool diffs, and keepmonaco-editorfor the editor and the Compare view.Attribution matters here: the minimap and the Markdown outline were @qqqqqf-q's work. Closing this PR is the intended way to say those should stay.
Validation
Run locally on this branch:
pnpm --filter @memohai/web typecheck— passpnpm --filter @memohai/desktop typecheck(includes the runtime build) — passpnpm exec vitest run --project web— 288 files / 2622 tests passpnpm lint— 0 errors (warnings only, all pre-existing)pnpm --filter @memohai/web build— pass; nomonacoreference remains indist/assetsOne caveat on the test run:
src/pages/oauth/mcp-oauth-security.test.tsfails intermittently when the whole web project runs in parallel. The same file fails on a clean worktree of the base commit (5db320a) with the same unhandled-rejection signature, and it passes when run alone on this branch; it is unrelated to this change.Browser verification (headless Chromium through Playwright, against a temporary harness page that mounts the real components; the harness is not committed):
ts,textanddifffences render highlighted rows (thetextfence is the language-key collision the custom router exists for), CodePanel copy button present, no console errors+/-rowsv-model,applyEdits()reaches the host,getText()returns the live draft, edit survives a theme switch and av-showcyclemodelValueexternally (disk reload / JSON “Format”) shows the new text instead of a retained draft, andfocus()after a queued rebuild lands in the live editorNot verified: Electron packaging (
build:dir), Docker/dev stack, and large-file (>10k lines) performance. No automated test covers the edit-session lifecycle; it was only exercised in the browser run above.Screenshots / Recordings
No screenshot is attached: the agent had no upload channel, and local file paths are not reviewable evidence. The verification above was done with a real browser (headless Chromium) on this branch. To reproduce locally:
pnpm --filter @memohai/web dev, open a conversation that streams a fenced block, open a file from the workspace, trigger a conflict chip → Compare, and open the MCP import dialog.Human QA
Additional Context
Please check before merging
Rendering and interaction on this branch (in priority order):
difffences are full width while plain fences stay fit-to-content; horizontal scrolling works on long lines; copy still copies the whole block.edit/writeshow the server diff;apply_patchshows one diff per file when the server sent a unified diff and falls back to the raw*** Begin Patchtext otherwise; long diffs stop at24rem.Cmd/Ctrl+S, dirty dot, undo/redo; drag the panel narrow/wide; hide it (tab switch) and come back.Benefits and trade-offs
See Decision this PR asks for above for the full ledger (measured vs structural), the removed capabilities with their authors, and the behaviour differences from Monaco. Short version: one runtime instead of two, fewer dependencies, and diff surfaces that gain hunk collapsing — at the cost of the minimap, sticky scroll, Monaco language services and virtualized large-file rendering.
Requires
markstream-vue >= 2.0.31andstream-diffs >= 0.0.5; both are pinned here.