refactor(viewer): extract scroll pending/pin machine into a pure reducer#41
Merged
Conversation
Startup benchmark (
|
| build | mean | ratio | verdict |
|---|---|---|---|
| baseline (main@cfb3815) | 784.2ms ± 33.6ms | — | |
| PR | 757.8ms ± 9.8ms | 0.97× | ✅ ok |
Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.
denolfe
added a commit
that referenced
this pull request
Jul 26, 2026
- refactor: split breadcrumb and ancestor-stack vocabulary (#45) (4fc9a88) - refactor(viewer): consolidate view state into a store hook (#44) (e39c971) - refactor(viewer): extract nav-intent consumer into a pure dispatcher (#43) (8cbde71) - refactor: consolidate heading/overlay geometry into a Fold module (#42) (bc77a33) - refactor(viewer): extract scroll pending/pin machine into a pure reducer (#41) (a2e8062) - feat(viewer): add a keyboard shortcut help drawer (#40) (cfb3815) - feat(viewer): breadcrumb trail for relative-link navigation (#39) (65ffb0e)
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.
Extracts the Viewer's scroll retry and pin orchestration into a pure reducer, giving the repo's highest-churn code a real unit-test seam. Behavior is preserved except one deliberate simplification (below).
The pending, pin, and frame-retry logic lived in a 160-line effect wired through four mutable refs, reachable only through slow integration tests. Six of the last eight feature PRs churned this surface, and the flicker and nav-correctness bugs both had to be chased without a unit seam.
Key Changes
pendingReducersrc/app/lib/pending-reducer.tsowns the machine state,{ pending, isSwap }. It maps events (issueJump,pinJump,userScroll,frameTick) to effects (scrollBy,repositioned).Viewer.tsxresolves the scrollbox geometry into a plain value and applies the reducer's effects. The four refs collapse to one state ref plus the unrelated notify refs.userScrollpath off the scroll watcher. A clamped no-op keypress (for example, down-arrow already at the bottom) no longer cancels a pin. This is the one intentional behavior change.docs/ARCHITECTURE.mdnow describes the reducer seam instead of the old ref-based mechanism.Design Decisions
Resolution(a plain{ delta, reached } | null, the delta to scroll and whether the target is in range) each frame and feeds it in as aframeTick. This keeps the reducer pure and target-kind-agnostic, so the interface is the test surface. It mirrors the existing puremapKey/dispatchsplit.reached || fullyMounted, matching the originaldone || fullyMounted. A pin aimed past a now-shorter document still settles once mounting finishes, so the navigation cover (the opaque panel shown during a doc swap) still drops.issueJumpfiresrepositionedwhen it supersedes an in-flight swap pin. The original dropped the cover incidentally through the scroll watcher; the single-supersede design makes that explicit so the cover cannot stick.Overall Flow
Previously the same logic ran inside one effect over four refs with no seam a test could reach. The reducer is now a pure function driven by the adapter, and every jump-into-unmounted-content path routes through it.