Fix(collapse): fix race condition when rapidly clicking accordion triggers#41893
Open
mironovsergey wants to merge 2 commits intotwbs:mainfrom
Open
Fix(collapse): fix race condition when rapidly clicking accordion triggers#41893mironovsergey wants to merge 2 commits intotwbs:mainfrom
mironovsergey wants to merge 2 commits intotwbs:mainfrom
Conversation
- Match active selector during transition (handle .collapsing without .collapse) - Track opening direction with _isShowing flag - Filter active children by shared triggers to support multiple targets per trigger - Only block when sibling elements are opening, not when they're closing Fixes twbs#41883
Author
|
I've added a test to cover the race condition scenario. The test rapidly clicks three accordion triggers in sequence and verifies that only the first panel remains open. |
|
Hi. You beat me to it. I checked your solution manually, it works. That's how it was before: before.mp4And so now: after.mp4 |
|
The test is working, all karma tests are also completed with the new change |
|
PLS upload to main branch |
Author
This PR needs a code review and approval from maintainers before it can be 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.
Description
Fixes a race condition in the Collapse component that can cause multiple accordion panels to open simultaneously when rapidly clicking different triggers in sequence. Accordion behavior should ensure that opening one panel closes any other open panel within the same parent.
Problem
When rapidly clicking different accordion triggers in sequence, multiple panels can remain open.
Steps to reproduce:
Root causes identified:
SELECTOR_ACTIVES- the selector.collapse.show, .collapse.collapsingis incorrect because.collapse.collapsingnever matches: when.collapsingis added,.collapseis removed (and vice versa). As a result, elements in transition were not reliably detected.activeChildren.length && activeChildren[0]._isTransitioningonly inspected the first active element and did not distinguish between opening vs closing transitions, causing improper blocking logic.During the investigation, I also discovered a test case
should allow accordion to target multiple elements, which verifies that a single trigger can control multiple targets. The same race condition bug affects this scenario as well - when rapidly switching between triggers, all corresponding panels open.Solution
SELECTOR_ACTIVESto.collapse.show, .collapsingto properly match elements during transition._isShowingflag to track the opening animation direction.activeChildrenby shared triggers - elements controlled by the same trigger should not block each other (this enables proper handling of multiple targets per trigger)._isShowingflag across all active elements instead of checking_isTransitioningon the first one only.Type of changes
Checklist
npm run lint)Related issues
Fixes #41883