Skip to content

web: highlight diffs with Highlights and fall back to Shiki without WebAssembly - #8492

Merged
unknwon merged 1 commit into
mainfrom
jc/diff-highlights
Nov 11, 2026
Merged

unknwon merged 1 commit into
mainfrom
jc/diff-highlights

Conversation

@unknwon

@unknwon unknwon commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Diff highlighting now uses @pierre/diffs' Highlights tokenizer, which runs on WebAssembly SIMD, instead of Shiki's JavaScript regex engine.

  • Highlights by default. The shared diff worker pool now sets preferredHighlighter: "highlights". Highlights bundles its own lexers, so the browser no longer fetches a Shiki grammar for each language in the diff.
  • Automatic fallback. At startup, canUseWASM() from @pierre/diffs checks whether WebAssembly with SIMD can be compiled and instantiated. When it cannot (for example, an older browser, or a CSP without wasm-unsafe-eval), diffs use shiki-js as before, and the console logs WebAssembly SIMD is unavailable, falling back to Shiki for diff highlighting. once per page load.

Link to the issue: n/a

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code or have provided the test plan. (if applicable)
  • I have added an entry to CHANGELOG. (if applicable)

Test plan

  1. pnpm run build and pnpm run lint in web/ pass.
  2. Build with -tags prod, open a commit that changes a Go file and a TypeScript file, and confirm both diffs are syntax highlighted. The network panel shows the highlights chunk and no Shiki engine or grammar chunks, and the console has no fallback message.
  3. Remove WebAssembly before the app loads (e.g., an init script running delete globalThis.WebAssembly) and open the same commit. The console logs the fallback message, the network panel shows shiki, engine-javascript, and the go and typescript grammars, and both diffs are still highlighted.

Screenshots

Commit page loaded directly (on top of #8447) with a Go and a TypeScript change.

Highlights (WebAssembly available) Shiki fallback (WebAssembly removed)
Highlights Shiki fallback

AI usage

The change, the verification, and this description were written by Amp (Claude Opus 5.5), directed and reviewed by the author.

@unknwon
unknwon merged commit 24fd5a4 into main Nov 11, 2026
@unknwon
unknwon deleted the jc/diff-highlights branch November 11, 2026 21:03
appthin added a commit to appthin/gogs-plus that referenced this pull request Nov 12, 2026
Brings in the 0.14.4 security and bug fixes (gogs#8439, gogs#8472, gogs#8478, gogs#8480-gogs#8484,
gogs#8486, gogs#8488), the Highlights-based diff highlighter for the web UI (gogs#8492,
gogs#8434, gogs#8435), absolute entrypoint paths for the SPA shell (gogs#8447), Docker
workflow updates (gogs#8463, gogs#8475), and housekeeping.

Fork-specific code is preserved: CodeQL workflow, login bans, sign-in
protection, the -plus release pipeline, and the rewritten README.
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