Prevent repeated preview re-renders with async Shiki highlighting#111
Closed
tnhu wants to merge 3 commits intopanphora:mainfrom
Closed
Prevent repeated preview re-renders with async Shiki highlighting#111tnhu wants to merge 3 commits intopanphora:mainfrom
tnhu wants to merge 3 commits intopanphora:mainfrom
Conversation
panphora
pushed a commit
that referenced
this pull request
May 2, 2026
) Async highlighters like Shiki were causing an infinite re-render loop: onChange fired on every updatePreview() call, including renders triggered by the highlighter resolving — which re-entered the cycle. Centralize change notification behind _notifyChange() and only fire it on real content changes (input events and setValue() with a different value), not on every render. Update the Shiki docs/example to use a pendingHighlights guard and editor.updatePreview() instead of OverType.setCodeHighlighter() to refresh, removing the second source of recursion. Adds tests for single-fire on setValue, ignoring render-only updates, and non-recursive preview refresh. Co-authored-by: Tan Nhu <tannhu@gmail.com>
Owner
|
Merged in 35d93fd via cherry-pick (rebuilt dist/ locally rather than carrying it in the merge). Original commits and authorship by @tnhu preserved on the resulting commit. Thanks for the fix — this is a real footgun for anyone wiring up Shiki, and the change to Will ship in the next release. |
panphora
added a commit
that referenced
this pull request
May 2, 2026
Owner
|
Shipped in v2.3.7 (commit 35d93fd). Centralized change notification behind Thanks @tnhu for the fix and the test cases. |
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 by cubic
Fixes the
shikisyntax highlighting re-render loop by makingonChangefire only on real content changes and updating docs/examples to use guarded, cached async highlighting. Editors stay stable while highlights load; distribution files are restored.Bug Fixes
_notifyChange();onChangenow fires on input and whensetValueactually changes content, not during render; safe to callupdatePreview()insideonChange.pendingHighlightsguard; switched toeditor.setCodeHighlighterandeditor.updatePreview()to avoid feedback loops.setValue, ignoring render-only updates, and non-recursive preview refresh.Refactors
dist/*for distribution.Written for commit 9035858. Summary will update on new commits.