Skip to content

feat(DockView): preventing access to objects after dispose#1054

Merged
ArgoZhang merged 2 commits into
masterfrom
fix-layout
Jul 2, 2026
Merged

feat(DockView): preventing access to objects after dispose#1054
ArgoZhang merged 2 commits into
masterfrom
fix-layout

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Jul 2, 2026

Copy link
Copy Markdown
Member

Link issues

fixes #1053

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

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

Summary by Sourcery

Bug Fixes:

  • Prevent DockViewV2 from invoking JS initialization or post-render logic after the component has been disposed.

@bb-auto bb-auto Bot added the enhancement New feature or request label Jul 2, 2026
@bb-auto bb-auto Bot added this to the v10.0.0 milestone Jul 2, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a disposal guard to DockViewV2 to prevent JS interop and render logic from running after the component has been disposed, avoiding access to invalid objects.

Sequence diagram for DockViewV2 disposal guard behavior

sequenceDiagram
    participant Blazor
    participant DockViewV2

    Blazor->>DockViewV2: OnAfterRenderAsync(firstRender)
    alt _disposed is false
        DockViewV2->>DockViewV2: set _layoutConfig
        DockViewV2->>DockViewV2: InvokeInitAsync()
        alt _disposed is false
            DockViewV2->>JSRuntime: InvokeVoidAsync(init, Id, Interop, GetDockViewConfig)
        else _disposed is true
            DockViewV2-->>Blazor: Task.CompletedTask
        end
    else _disposed is true
        DockViewV2-->>Blazor: return
    end

    Blazor->>DockViewV2: DisposeAsync(disposing: true)
    DockViewV2->>DockViewV2: _disposed = true
    DockViewV2->>ThemeProviderService: unsubscribe OnThemeChangedAsync
    DockViewV2-->>Blazor: dispose complete
Loading

File-Level Changes

Change Details Files
Introduce a disposal state flag and guard lifecycle/interop methods to no-op after disposal.
  • Add a private _disposed boolean field to track component disposal state.
  • Set _disposed to true inside DisposeAsync when disposing is true before unsubscribing from ThemeProviderService.ThemeChangedAsync.
  • Short‑circuit OnAfterRenderAsync to return immediately when _disposed is true, preventing further post-render logic after disposal.
  • Update InvokeInitAsync to return a completed task without invoking JS interop when _disposed is true, avoiding initialization after disposal.
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#1053 Prevent DockViewV2 from accessing or using its internal objects/state after the component has been disposed.

Possibly linked issues


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 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 0165a51 into master Jul 2, 2026
3 checks passed
@ArgoZhang ArgoZhang deleted the fix-layout branch July 2, 2026 01:36

@sourcery-ai sourcery-ai 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.

Hey - I've left some high level feedback:

  • In OnAfterRenderAsync, the _disposed check happens only after base.OnAfterRenderAsync is awaited; if a render is triggered after disposal, the base implementation will still run, so consider short-circuiting before calling the base method to avoid any post-dispose work entirely.
  • Now that _disposed is used to guard JS interop in OnAfterRenderAsync and InvokeInitAsync, review other JS interop or async callbacks in this component to ensure they also check _disposed for consistent behavior after disposal.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `OnAfterRenderAsync`, the `_disposed` check happens only after `base.OnAfterRenderAsync` is awaited; if a render is triggered after disposal, the base implementation will still run, so consider short-circuiting before calling the base method to avoid any post-dispose work entirely.
- Now that `_disposed` is used to guard JS interop in `OnAfterRenderAsync` and `InvokeInitAsync`, review other JS interop or async callbacks in this component to ensure they also check `_disposed` for consistent behavior after disposal.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(DockView): preventing access to objects after dispose

1 participant