Skip to content

feat(highlight-stream): add virtualize prop for windowed rendering - #479

Merged
metonym merged 2 commits into
masterfrom
metonym/highlightstream-virtualization
Aug 1, 2026
Merged

feat(highlight-stream): add virtualize prop for windowed rendering#479
metonym merged 2 commits into
masterfrom
metonym/highlightstream-virtualization

Conversation

@metonym

@metonym metonym commented Jul 27, 2026

Copy link
Copy Markdown
Owner

HighlightStream renders every streamed line into the DOM, so a
long-running stream keeps growing the page's node count even though
each repaint stays cheap. There was no way to bound it the way
HighlightVirtual bounds a static document, and no shared windowing
code between the two components.

Add a virtualize prop that swaps the sealed-chunk session for
TokenizedDocument and renders only the scrolled window (plus
overscan), reusing the same checkpoint/resume primitive
HighlightVirtual uses. Caret, autoScroll, and on:done keep
working; on:highlight is skipped in this mode since materializing
full HTML every repaint would defeat the point of windowing, and
done no longer upgrades to a canonical re-parse, matching the
tradeoff HighlightVirtual already makes. The windowing math and
line-height measurement moved into a shared src/virtual-window.js,
which HighlightVirtual now uses too, with line height rounded to a
whole pixel so the sizer/translateY math stays aligned with the
always-integer scrollTop under frequent repaints.

Docs and an example (streaming 1,500 lines with a live rendered-node
counter and pause/resume controls) are included on the main docs page
and the HighlightStream preview route.

Risk

Scoped to a new opt-in prop (default false) plus a pure refactor of
HighlightVirtual's existing windowing code into a shared module; the
non-virtualize path is unchanged. Main risk is in the shared
virtual-window.js math, covered by unit tests and the existing
HighlightVirtual e2e suite plus new virtualize-specific e2e tests.

metonym added 2 commits July 30, 2026 11:16
HighlightStream renders every streamed line into the DOM, so a
long-running stream keeps growing the page's node count even though
each repaint is cheap. There was no way to bound it the way
HighlightVirtual bounds a static document.

Add a virtualize prop that swaps the sealed-chunk session for
TokenizedDocument and renders only the scrolled window (plus
overscan), reusing the same checkpoint/resume engine primitive.
Caret, autoScroll, and on:done keep working; on:highlight is skipped
since materializing full HTML every repaint would defeat the point of
windowing, and once done, output stays the streaming (non-
canonicalized) parse rather than upgrading to a canonical render,
the same tradeoff HighlightVirtual already makes.

The windowing math and line-height measurement are pulled out into a
shared src/virtual-window.js, which HighlightVirtual now uses too.
Line height is rounded to a whole pixel there: a fractional value
puts the sizer/translateY math at a different sub-pixel offset than
the always-integer scrollTop on every repaint, which is invisible for
a one-off scroll but reads as a visible jitter under the streaming
case's much higher repaint frequency.
Add a docs example streaming 1,500 lines through virtualize with
autoScroll, tracking rendered [data-line] node count live to show it
stays bounded. Wired into the main docs page and the (unlisted)
HighlightStream preview route.

simulateStream's returned stop function now also carries pause()/
resume(), so the demo can freeze the stream and continue from where
it left off instead of only being able to restart from scratch. The
demo exposes this as a Pause/Resume button next to the existing
Replay control.
@metonym
metonym force-pushed the metonym/highlightstream-virtualization branch from 22f95a6 to 6a90b65 Compare July 30, 2026 18:19
@metonym
metonym temporarily deployed to metonym/highlightstream-virtualization - svelte-highlight PR #479 July 30, 2026 18:19 — with Render Destroyed
@metonym
metonym merged commit 44fe7aa into master Aug 1, 2026
3 checks passed
@metonym
metonym deleted the metonym/highlightstream-virtualization branch August 1, 2026 00:25
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