Repository navigation
fix: measure only on-screen block toolbars (0.4.3) - #1
Merged
Merged
Conversation
…hange Every code, diagram, and table toolbar registered its own capturing window scroll listener and requested one animation frame per scroll event. Each frame measured its block with getBoundingClientRect and called classList.add or classList.remove, whether or not the block was on screen and whether or not the state changed. DOMTokenList add and remove rewrite the class attribute even when the token is already in the requested state, so a long transcript produced one attribute mutation and one layout read per block per scroll frame (measured: ~600 mutation records and ~2,000 rect reads per second while scrolling a 64k px transcript). watchStickyHeader replaces the per-block listeners: one IntersectionObserver tracks which blocks are on screen, one capturing scroll/resize listener is attached only while some block is, each pass reads every on-screen block before writing any class, and the class is toggled only when the stuck state flips. Without IntersectionObserver every block counts as on screen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Block toolbars stop costing work per scroll frame: only on-screen blocks are measured, through one shared listener, and the "scroll" class is written only when it flips. No API change, so this is a patch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Coverage Report for Unit
File CoverageNo changed files found. |
Coverage Report for All
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Covers the server no-op watch, an intersection delivered after stop, a stop before the wrapper attaches, and an update on or off screen. Header wrapper getters read the required ref directly, and update() recomputes through isStuck, which already clears a fullscreen block. Co-Authored-By: Claude Opus 5 <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
Every code, diagram, and table toolbar registered its own capturing window scroll listener and requested an animation frame per scroll event. Each frame measured its block with
getBoundingClientRectand calledclassList.add/remove— for every block on the page, on screen or not, whether or not the state changed.DOMTokenListadd/remove rewrite theclassattribute even when the token is already in the requested state, so every block produced a mutation record and a layout read per scroll frame.Measured in a host app scrolling a 64k px transcript: ~600 mutation records/s and ~2,000 rect reads/s from toolbars alone. The
chat-testexample page showed ~5,000 mutation records/s (code, diagram, and table headers).Change
runtime.watchStickyHeader(wrapper, header, fullscreen)replaces the per-block listeners:IntersectionObservertracks which blocks are on screen; an off-screen block cannot span the toolbar band, so it is cleared and never measured;scrollclass is toggled only when the stuck state flips;IntersectionObserverevery block counts as on screen (previous behaviour, minus redundant writes).Code, mermaid, and table headers use it;
onViewportScrollstays exported.After the change, the same host scroll measured 9 mutation records/s.
Tests
tests/coverage/sticky-header.test.ts: off-screen blocks are never measured, repeated scrolls in one state write nothing, leaving the screen clears the class and detaches the listener, registration waits for the wrapper ref,stop()clears the class.final-branches.test.tsx: an unmounted header's update schedules nothing (the per-instance rAF path no longer exists).npm test(888 passed),npm run typecheck,eslinton changed files,npm run build.Release
Includes the
chore: release 0.4.3bump (patch: no API change).🤖 Generated with Claude Code