Repository navigation
Let an explicit equals decide when tracked selections notify - #113
Merged
Merged
Conversation
The tracked forms of Retree.select and useSelect notified and re-rendered when a dependency changed even when the caller's equals reported the previous and next selections equal. The dependency check exists so a selector returning a stable node reference still notifies when that node's content changes; it now applies only to the default comparison. With equals supplied, an equal re-run keeps the previous reference and stays silent.
ryanbliss
force-pushed
the
fix/equals-gates-tracked-select
branch
from
September 8, 2026 22:04
b91570d to
36a2f1c
Compare
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
The tracked forms of
Retree.select(selector, onChange, { equals })anduseSelect(selector, { equals })notified and re-rendered whenever a tracked dependency changed, even whenequalsreported the previous and next selections equal.createRetreeTrackedSelectionObserver.evaluateemitted ondependenciesChangedregardless ofequals, andrefreshTrackedSelectStateminted a new container unless the selection, reads and sources were all unchanged.Neo hit this with a list grid that selects the projected row order under a localized-text sort with
equals: sameEntryIds. An edit to a graded text that leaves the order alone re-ran the selector (correct) and then re-rendered the whole grid (wrong), when only the cell showing that text should update.Solution
The dependency check exists so a selector returning a stable node reference still notifies when that node's content changes. It now applies only to the default comparison. A new shared helper,
hasTrackedSelectionChanged, holds that rule for both forms: withequalssupplied it is the whole answer; without it, a reference change or a reads change counts. The React tracked form now keeps its container on the same condition as the node form (selectedEqual && sourcesEqual), still swapping sources and refreshing its snapshot when the reads move.Specs cover both forms: a rank write that re-runs a sorted-ids selector without changing the order neither notifies nor re-renders, and a write that reorders does. Both fail on
main.Alternatives
onChangeor memoize arounduseSelectthemselves. That leavesequalsdocumented as stabilizing outputs while it does not, anduseSelecthas no hook to suppress a re-render after the fact.Verification
npm run typecheck,npm run test(1699 passing),npm run doctor,npm run lint:architecture.