Skip to content

Ensure DOM event handlers are triggered like Blazor does it #518

@egil

Description

@egil

bUnit currently triggers DOM event handlers like this:

  • For bubbling events, e.g. @onclick events, it starts with the trigger element and invokes the Blazor event handler (if present), and then walking up the DOM tree and finding all parent elements with a Blazor event handler attached matching the triggered event type, and triggers those as they are found. If a "stop event propagation" or disabled event is found, the bubbling stops.
  • For non-bubbling events, the Blazor event handler bound to the triggering element is invoked.
  • In both cases, if no Blazor event handler is found, a MissingEventHandlerException is thrown. For bubbling events, at least one Blazor event handler must be found in the DOM tree.
  • If an Blazor event handler is triggered after it has been removed/disposed, i.e. because the owning component has been disposed/removed from the render tree, an exception is thrown by the Blazor Renderer (a There is no event handler associated with this event. EventId XX exception).

This works well, and should align with how Blazor does it. However, it is unclear what Blazor does in the following scenario (inspired by #517):

Suppose we have (maybe multiple) components that render out something like the following markup:

<tr onclick="...">
  <td onclick="...">
    <button onclick="...">

The user triggers the event handler bound to the button element, which causes the DOM to be updated, such that the td elements onclick handler is removed.

  1. Does Blazor still trigger the td and tr onclick event handlers?
  2. Does Blazor only trigger the tr onclick event handler that is still bound?
  3. or does the bubbling stop, i.e. no more event handlers are triggered?

My experiments up till now has been inconclusive, so hoping somebody, perhaps @SteveSandersonMS, can help clear things up.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginvestigateThis issue require further investigation before closing.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions