Fix StyledText crash with dynamic custom_highlights#2170
Open
KlausUllrich wants to merge 1 commit into
Open
Conversation
Include custom_highlights in NodeContext::PartialEq so highlight changes trigger re-rendering, and add bounds validation in merge_custom_highlights() to skip highlights that exceed chunk bounds after clipping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Problem
StyledText::with_runspanics with "invalid text run" whencustom_highlightsare used with dynamically updating content viaTextView::markdown()orTextView::html().This affects any use case where:
with_highlights()is used to apply custom stylinggpui/src/elements/text.rs:251Root Cause
Two issues in
text/node.rs:1. NodeContext equality ignores custom_highlights
The
PartialEqimpl forNodeContextintentionally excludescustom_highlightsfrom comparison. When highlights change but text content doesn't, GPUI's diffing skips re-rendering and reuses staleInlineelements with mismatchedTextRunindices.2. merge_custom_highlights missing bounds validation
merge_custom_highlights()clips highlight ranges to chunk boundaries but doesn't validate the result. When chunks from parsed markdown and highlights from the caller originate from different parse cycles, clipping can producelocal_end > chunk_len, leading to the panic downstream.Fix
custom_highlightsinNodeContext::PartialEqso highlight changes trigger re-renderingmerge_custom_highlights()to skip highlights that exceed chunk bounds after clippingBoth changes are minimal and defensive. The equality fix ensures correctness; the bounds check adds safety for edge cases during content transitions.
Testing
Reproduced in a production log viewer with rapid content updates and custom syntax highlighting. Both fixes together eliminate the crash class.