Skip to content

fix(Drawer): prevent close and reopen races - #8771

Merged
ArgoZhang merged 5 commits into
mainfrom
fix/drawer-close-races
Nov 17, 2026
Merged

ArgoZhang merged 5 commits into
mainfrom
fix/drawer-close-races

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Link issues

fixes #8770

Summary By Copilot

  • Guard repeated Drawer close requests, including asynchronous backdrop callbacks.
  • Preserve replacement drawers when an earlier close callback completes.
  • Cancel stale animation frames without restarting pending same-state animations on every render.
  • Release the body scroll lock after the last drawer closes or is disposed, including simultaneous closes.
  • No public API, dependency, packaging, or CI changes.

Regression?

  • Yes
  • No

The version introducing these lifecycle bugs has not been determined.

Risk

  • High
  • Medium
  • Low

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 --check and 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:

Replacement drawer B remains visible after drawer A closes once

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

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:

  • Prevent concurrent and stale Drawer close callbacks from closing replacement or reopened drawers.
  • Ensure Drawer animations, body scroll locking, and disposal remain consistent during rapid, simultaneous, or repeated state changes.

Enhancements:

  • Make drawers focusable for keyboard interactions and reuse shared sample content with the standard close control.

Tests:

  • Add regression coverage for focusability and concurrent close requests.

ArgoZhang and others added 2 commits November 17, 2026 15:49
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

API

Make backdrop and programmatic close requests share a guarded asynchronous close path so callbacks and state changes run only once.

  • src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs L219-221, L228-232, L237-270

Implementation

Coordinate Drawer animation frames and body-scroll restoration across rapid state changes, concurrent drawers, and disposal.

  • src/BootstrapBlazor/Components/Drawer/Drawer.razor.js L5-12, L112-132, L163-168 (+7 small edits)
  • src/BootstrapBlazor/Components/Drawer/DrawerContainer.cs L119-123

UI

Add keyboard focusability to the Drawer and reuse shared content with a close button in the Drawer samples.

  • src/BootstrapBlazor.Server/Components/Samples/Drawers.razor L70-76 (+4 small edits)
  • src/BootstrapBlazor.Server/Components/Samples/Drawers.razor.cs L1, L67
  • src/BootstrapBlazor/Components/Drawer/Drawer.razor L5

Tests

Cover Drawer focusability and ensure concurrent close requests do not duplicate callbacks or state notifications.

  • test/UnitTest/Components/DrawerTest.cs L21 (removed lines), L78-86, L302-342

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added the bug Something isn't working label Nov 17, 2026
@bb-auto bb-auto Bot added this to the v11.1.0 milestone Nov 17, 2026

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6fc94a5) to head (3a40154).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit 3a40154

#8770 bug(Drawer): rapid close and reopen operations race · 4 of 4 met

# Requirement Status Notes
1 Prevent repeated concurrent closes from running close callbacks more than once. ✅ Met CloseAsync sets _isClosing before awaiting callbacks and ignores another close while the first is in progress.
2 Prevent an old close callback or animation from affecting a replacement or reopened drawer. ✅ Met DrawerContainer.OnCloseAsync clears only the option it closed; the JS module cancels a pending animation when execution switches states.
3 Restore scrolling only when no other open drawer requires the lock. ✅ Met restoreBodyScroll checks other visible drawers that do not allow body scrolling before removing the lock.
4 Restore the body scroll lock when an open drawer is disposed. ✅ Met dispose removes the drawer's visible state and calls restoreBodyScroll.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@ArgoZhang
ArgoZhang merged commit 4ea83f8 into main Nov 17, 2026
4 checks passed
@ArgoZhang
ArgoZhang deleted the fix/drawer-close-races branch November 17, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Drawer): rapid close and reopen operations race

1 participant