Skip to content

fix: always call initSyntax on mount to prevent lost highlighting#64

Open
voglster wants to merge 1 commit intoMrWangJustToDo:mainfrom
voglster:fix/syntax-highlight-remount
Open

fix: always call initSyntax on mount to prevent lost highlighting#64
voglster wants to merge 1 commit intoMrWangJustToDo:mainfrom
voglster:fix/syntax-highlight-remount

Conversation

@voglster
Copy link

Summary

  • Fixes syntax highlighting being lost when DiffView is unmounted and remounted with the same file content
  • Removes the overly-aggressive guard condition in the syntax init effect across all framework packages (React, Vue, Svelte, Solid)
  • initSyntax() is already idempotent, so calling it unconditionally is safe and efficient

Root Cause

The global File cache in @git-diff-view/core causes initRaw()#syncSyntax() to copy highlighter metadata (highlighterName, highlighterType) from cached File objects into a fresh DiffFile. The syntax effect then sees matching metadata and skips initSyntax() entirely, leaving syntax lines as null.

Fixes #63

Syntax highlighting is lost when DiffView is unmounted and remounted
with the same file content. The global File cache causes initRaw() →
#syncSyntax() to copy highlighter metadata from cached File objects
into a fresh DiffFile, making the syntax effect's guard condition
evaluate to false and skip initSyntax() entirely.

initSyntax() is already idempotent — when syntax is initialized with
a matching highlighter, it efficiently re-syncs syntax line references
without recomputing. Remove the guard condition and always call
initSyntax() when highlighting is enabled.

Fixes MrWangJustToDo#63
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.

Syntax highlighting lost after unmount/remount of DiffView

1 participant