Repository navigation
fix(Drawer): prevent close and reopen races - #8771
Conversation
Guard repeated close requests, preserve replacement drawers, and cancel stale animation frames. Restore body scrolling without unlocking other open drawers. Fixes #8770 Co-authored-by: Copilot <[email protected]>
Avoid restarting same-state animations on repeated renders and restore scrolling when the final hide animation completes. Co-authored-by: Copilot <[email protected]>
Reviewer's GuideAPIMake backdrop and programmatic close requests share a guarded asynchronous close path so callbacks and state changes run only once.
ImplementationCoordinate Drawer animation frames and body-scroll restoration across rapid state changes, concurrent drawers, and disposal.
UIAdd keyboard focusability to the Drawer and reuse shared content with a close button in the Drawer samples.
TestsCover Drawer focusability and ensure concurrent close requests do not duplicate callbacks or state notifications.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8771 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 663 663
Lines 30339 30350 +11
=========================================
+ Hits 30339 30350 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 3a40154 #8770 bug(Drawer): rapid close and reopen operations race · 4 of 4 met
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs" line_range="256" />
<code_context>
/// <para lang="en">Backdrop Click Method</para>
/// </summary>
- public async Task OnContainerClick()
- {
- if (OnClickBackdrop != null)
- {
</code_context>
<issue_to_address>
**Close effects run after reopen**
When the parent or caller reopens the drawer, or reapplies `IsOpen=true`, during the close delay, `CloseAsync` resumes without checking whether the drawer reopened, invokes `OnCloseAsync`, and reports the current value through `IsOpenChanged`; the drawer stays visible while callers receive close side effects and may receive `true` as the change value.
After the delay, stop the stale close continuation if the drawer has reopened, and report the close request value rather than the reopened state.
Also at `src/BootstrapBlazor/Components/Drawer/Drawer.razor.js:129`, `src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs:249`, `src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs:257`.
</issue_to_address>
### Comment 2
<location path="src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs" line_range="119-121" />
<code_context>
- _option = null;
- StateHasChanged();
+ if (ReferenceEquals(_option, option))
+ {
+ _option = null;
+ StateHasChanged();
+ }
</code_context>
<issue_to_address>
**Reopened drawer disappears**
When the same `DrawerOption` instance is shown again before its earlier close callback completes, `OnCloseAsync` passes the `ReferenceEquals` check and clears `_option`, so the earlier close removes the newly shown drawer.
Track the active show operation separately from the `DrawerOption` reference, and clear `_option` only when the completing close belongs to the current show.
</issue_to_address>
### Comment 3
<location path="src/BootstrapBlazor/Components/Drawer/Drawer.razor.js" line_range="187" />
<code_context>
+ body.classList.add('drawer-overflow-hidden');
+ }
+ else {
+ restoreBodyScroll(el, body);
+ }
+ }
</code_context>
<issue_to_address>
**Scroll unlocks during closing**
When the last non-scrolling drawer begins an animated close, `restoreBodyScroll` excludes the drawer being closed, so it removes the body lock as soon as the hide starts when no other blocking drawer is open. The drawer remains visible through its 320 ms hide animation, allowing page scrolling before the final hide completes.
For animated hides, defer releasing the body lock until the hide completes, while retaining the immediate release for non-animated hides.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs:256, src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs:121, src/BootstrapBlazor/Components/Drawer/Drawer.razor.js:187
Link issues
fixes #8770
Summary By Copilot
Regression?
The version introducing these lifecycle bugs has not been determined.
Risk
Changes shared close, animation, and body-scroll coordination. Browser checks cover repeated closes, replacement and reentrant opening, rapid reopening, repeated same-state execution, simultaneous closes, and disposal.
Verification
Manual (required)
Automated
dotnet build src\BootstrapBlazor\BootstrapBlazor.csproj --no-restore -v minimal— passed for net6.0 through net11.0, with 0 warnings and 0 errors.dotnet format whitespace src\BootstrapBlazor\BootstrapBlazor.csproj --no-restore --verify-no-changes --include src\BootstrapBlazor\Components\Drawer\Drawer.razor.cs src\BootstrapBlazor\Components\Drawer\DrawerContainer.cs— passed.node --check src\BootstrapBlazor\Components\Drawer\Drawer.razor.js— passed.git diff --checkand changed-file UTF-8-without-BOM checks — passed.Browser verification against an isolated Blazor Server page referencing the modified library — passed: concurrent close requests invoke the callback once; replacement drawers survive old and reentrant close callbacks; reopening cancels an old hide; repeated same-state calls do not postpone completion; simultaneous closes release scrolling; closing one of two open drawers preserves the scroll lock; disposal releases it.
Quick review found and fixed two intermediate regressions: simultaneous closes retaining the scroll lock, and repeated renders restarting the hide timer. Both were reproduced before the fixes and verified afterward using the real Drawer module in the browser.
No unit tests were added, modified, or run, following repository policy for JavaScript-related changes. Automated verification above means build and static checks, not unit tests.
After two concurrent closes of A, its callback ran once and replacement B remained visible:
Packaging changes reviewed?
☑️ Self Check before Merge
This fixes existing behavior without new APIs or visual design changes, so no documentation or demo source changes are needed. The branch starts from the latest fetched main.
Summary by Sourcery
Harden Drawer lifecycle handling to prevent close and reopen races while preserving correct animation and body scroll behavior.
Bug Fixes:
Enhancements:
Tests: