Repository navigation
Proposed Root-Cause Fix for #1246 #1352
Unanswered
aryan-iconic
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I’ve been digging deeper into #1246, particularly around the race condition mentioned in the recent comments, and I think I’ve identified the state transition that allows the invalid
activeItemIdto occur.From tracing
activeItemIdthrough the reducer andgetActiveItem()logic, it appears to be a flattened positional index across all collections.The problematic sequence seems to be:
The current
setCollectionsreducer replaces the collections but doesn't revalidate the existingactiveItemId.Proposed approach
Rather than only adding a null check at the point of failure, I'm considering fixing the state invariant at the
setCollectionsboundary:The idea is:
defaultActiveItemIdrather than clamping to the last item, since the item at that position may represent completely different content after an async update.focus,reset, andmouseleavetransitions.I’m also considering keeping a defensive check in the
Enterhandler:This would be a second layer of protection in case an invalid state is ever reached through another path, while importantly avoiding
preventDefault()when there isn't actually an active item to select.What I'd like to validate
Before opening a PR, I'd really appreciate feedback on whether this is the right place to enforce the invariant.
In particular:
setCollectionsbe responsible for revalidatingactiveItemIdwhen the collection size changes?defaultActiveItemIdpreferable to clamping to the last valid index or setting it tonull?getActiveItem()returnsnullmatch the intended behavior?onKeyDowncheck in addition to the reducer-level fix, or should the fix be kept solely at the state boundary?I’ve also added deterministic regression tests for the stale-index scenario and verified that they fail against the existing implementation and pass with the proposed changes.
I’d appreciate any feedback on the approach before I turn this into a PR. I’d rather make sure the state semantics are correct than just suppress the production error.
All reactions