Fix skip-list edge cases with zero totals and negative values - #555
Merged
Conversation
- Return early from `find` when `total <= 0` to avoid crashes on empty lists - Clamp `targetValue` to >= 0 with `Math.max(0, targetValue)` after the `Math.min` call - Clamp `value` in `set` to >= 0 with `Math.max(0, value)` to prevent negative heights corrupting layout
Tests cover: - find() with zero total (all items have height 0) - find() with empty list (length 0) - find() with negative targetValue (clamped to 0) - find() with targetValue exceeding total (clamped to last item) - set() with negative value (clamped to 0) - set() with valid value (baseline behavior) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
The failures of |
Merged
Contributor
|
In |
3 tasks
This was referenced Apr 10, 2026
Merged
Merged
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
This PR fixes three edge cases in
vertical-collection/src/-private/data-view/skip-list.jsthat can cause crashes or corrupted layout state when item heights are zero or negative.Fix 1: Early return in
findwhentotal <= 0When a
SkipListis constructed with items that all have zero height (e.g. items not yet measured),totalwill be0. The previous code would proceed to computeMath.min(total - 1, targetValue)→Math.min(-1, targetValue), resulting in a negativetargetValuethat immediately triggers the assertiontargetValue must be greater than or equal to 0and throws.The fix returns
{ index: 0, totalBefore: 0, totalAfter: 0 }early whentotal <= 0, matching the same early-return pattern already used forlength === 0.Fix 2: Clamp
targetValueto >= 0Even after the
total <= 0guard, iftargetValueis negative (e.g. a negativescrollTopduring rubber-band scroll on iOS),Math.min(total - 1, targetValue)may still yield a negative value. AddingMath.max(0, targetValue)after theMath.minensures the value stays in bounds before the assertion.Fix 3: Clamp
valueinsetto >= 0When measuring item heights, a layout engine can occasionally return a negative or
-0value. Passing such a value tosettriggers the assertionvalue must non-negativeand throws, leaving the list in a partially-updated state. Clamping withMath.max(0, value)silently coerces bad measurements to0before the assertion, preventing corruption.Related issue: #208