{{ message }}
fix(List): preserve undefined values when grown past 32 elements - #2235
Merged
Merged
Conversation
The trie root was stored as `null` in two places (small-List constructor and the "origin within tail" branch of setListBounds), so a List grown past 32 elements while all values are `undefined` read them back as `null`. Normalize both to `undefined`, matching the rest of the file.
mateuszbielak1989-sketch
approved these changes
Jul 23, 2026
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.

Bug
A
Listgrown past 32 elements while every value isundefinedreads those values back asnull, corruptingget, iteration,toArray,equalsandhashCode.This affects any path that produces an all-
undefinedregion spanning the 32-element (tail → root) boundary —setSize,push(undefined), mutations, and theunshift/delete/shiftsequence from #2230.Root cause
A
Listrepresents an absent trie node asundefinedalmost everywhere (clear(),emptyList(), and the trie's own array holes viaremoveBefore). But_rootwas stored asnullin two spots:makeList(0, size, SHIFT, null, …)setListBounds:newRoot = nullFor small lists this is invisible (indices route to the tail, never the root). But once such a List grows past the next 32-element boundary, in-range indices route through
_root, and the read idiomnode && node.array[i]returns the falsy node itself —null && x === nullleaksnull, whereasundefined && x === undefinedreads correctly.Fix
Normalize both sites to
undefinedso an absent root has a single sentinel, consistent with the rest of the file. No reader change is needed:node && node.array[i]is correct once_rootisVNode | undefined. JSDoc is added onVNode/makeList/listNodeForto capture that shape ahead of the TypeScript migration.Notes
This supersedes #2230: that change guards the "Merge Tail into tree" step, but its condition starts with
oldTail && …, so it does not cover thesetSize(≤32).setSize(≥33)family (whereoldTailis itselfnull) —setSize(32).setSize(33)still returnsnullwith it applied.Tests
8 regression cases in
__tests__/List.ts(minimal repro + variants, the #2230 sequence, and anull-round-trips guard against over-correction). Full suite green (826 tests, incl. fast-check property tests).