ada-blazor-interop-pitfalls

Diagnose and fix Blazor JS interop failures including non-bubbling events, DotNetObjectReference leaks, and render-timing bugs.

Updated Jul 23, 2026
One-click install
npx skills add https://github.com/wubing7755/Ada --skill ada-blazor-interop-pitfalls-wubing7755
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ada-blazor-interop-pitfalls
Source: https://github.com/wubing7755/Ada/tree/main/skills/software-development/ada-blazor-interop-pitfalls
Command: npx skills add https://github.com/wubing7755/Ada --skill ada-blazor-interop-pitfalls-wubing7755

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Blazor .NET 6 JS interop failures are notoriously silent: unsupported event directives compile but never fire, DotNetObjectReference callbacks leak or get disposed mid-drag, bundled JS modules miss C#-invokable exports that bUnit tests cannot catch, and drag previews bounce because JS clears state before Blazor's render batch applies. This Skill provides verified root-cause patterns and fixes for each of these production failures. ## Core Features & Use Cases - Non-bubbling event fixes: Replace silently ignored @onmouseenter/@onmouseleave directives with a three-layer JS interop pattern (TypeScript listener registration, C# interop service, Razor component with re-registration guards). - Callback lifecycle management: Prevent DotNetObjectReference disposal errors and memory leaks with paired register/unregister/dispose patterns and WeakMap-based listener tracking. - Bundle export verification: Detect C#-invokable functions missing from the shipped JS bundle entry surface that bUnit's loose JSRuntime mode cannot catch, with Node regression tests against the entry surface. - Render-timing patterns: Fix drag/resize preview bounce by keeping JS preview state until Blazor's commit re-render applies, with bounded fallbacks for rejected commits. - Use Case: A hover flyout in your Blazor component library never triggers despite compiling cleanly. The Skill identifies mouseenter as non-bubbling, walks you through the TypeScript/C#/Razor three-layer fix, and gives you a verification checklist including browser console checks. ## Quick Start Ask the agent to diagnose why your Blazor hover event or drag-and-drop interop callback is not firing and to apply the appropriate fix pattern with verification steps.

Frequently Asked Questions about ada-blazor-interop-pitfalls

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does @onmouseenter compile but never fire in Blazor?

Blazor .NET 6 only supports bubbling events through its document-level event delegation, and mouseenter/mouseleave do not bubble. Razor does not validate event attribute names, so unsupported directives compile silently and become dead code. The fix is registering native listeners via JS interop.

How do I fix DotNetObjectReference disposed errors in Blazor drag and drop?

Ensure symmetric cleanup: call the JS unregister function before disposing the DotNetObjectReference, guard re-registration with a string identity check like _lastRegisteredPanelId, and wrap registration in try/catch for JSException when DOM elements are removed between renders.

Why does bUnit pass but the real browser reports Could not find JS function?

bUnit's JSRuntimeMode.Loose records every InvokeVoidAsync as successful without checking the function exists. If your bundle entry surface does not re-export the function from its implementation module, the shipped bundle lacks it. Add the export, rebuild, and write a Node test importing the entry surface.

How do I stop drag previews from bouncing back in Blazor WASM?

Keep the JS inline preview style when the commit is sent instead of clearing it synchronously. Blazor's re-render replaces the style attribute and self-cleans the preview. Poll a data-revision attribute at rAF cadence to detect the applied render, with a bounded fallback for rejected commits.

When should I not use this Skill for Blazor problems?

Do not use it for pure Blazor lifecycle or rendering issues like StateHasChanged timing or OnAfterRender ordering without JS involvement; those route to ada-blazor-interaction-pitfalls. Broad cross-layer audits belong to ada-blazor-ui-audit.

Which mouse events does Blazor .NET 6 support natively?

Blazor .NET 6 supports onclick, ondblclick, onmousedown, onmouseup, onmousemove, onmouseover, onmouseout, onmousewheel, and oncontextmenu out of the box. Any event directive outside this list compiles without error but is silently ignored at runtime.