Skip to content

Issue disposing a component's JS complement in a Blazor Web App using mixed render modes #62230

Open
@pkostaki

Description

@pkostaki

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

There is no reliable way for disposing a component's JS complement in a Blazor Web App using mixed render modes.

Additionally, the documentation confirms this behavior: DOM cleanup tasks during component disposal, suggesting the use of a MutationObserver on the component’s parent HTML element. However, this approach fails in scenarios where a higher-level ancestor (e.g., the parent of the parent) is removed. Using a MutationObserver on the entire document to catch such removals is inefficient.

Calling dispose JS method from the .NET side (during component disposal) to JavaScript doesn't work in apps with mixed render modes — the element mappings are cleared when navigating from a page with one render mode to another with a different render mode. ( ⚠ with Blazor Server or Blazor WebAssembly apps there is no such issue).

Please, check the attached sample.

Expected Behavior

component's element mapping is retained until its .NET side is disposed.

Steps To Reproduce

Run sample: BlazorMixedRenderModeIssueWebApp.zip

  • navigate to Counter page
  • navigate to Weather page

Exceptions (if any)

Image

.NET Version

9.0.300

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions