Skip to content

EventHandlerAttribute: enableStopPropagation and enablePreventDefault are swapped #10497

@FStolte

Description

@FStolte

Summary

The parameters enableStopPropagation and enablePreventDefault of the EventHandlerAttribute are swapped by the razor compiler, so that setting enableStopPropagation = true actually enables preventDefault, and vice versa.

Steps to reproduce

I added the following class to my project in order to add support for the "transitionend" event to blazor:

[EventHandler("ontransitionend", typeof(EventArgs), enableStopPropagation: true, enablePreventDefault: false)]
public static class EventHandlers { }

When I set @ontransitionend=SomeCallback on a div in one of my components, this is recognized immediately by the compiler, according to the syntax highlighting.
However, when I try to set @ontransitionend:stopPropagation on another div, this is not recognized (the whole string was red like an html-attribute). When I then start my app, I get an exception complaining about a malformed string, i.e. the unprocessed "@" in the html-attribute name.
Furthermore, adding @ontransitionend:preventDefault is recognized and handled by the compiler, when it should be disabled. Swapping the values for both parameters results in the exact opposite behavior.

Possible cause

enablePreventDefault = (bool)attribute.ConstructorArguments[2].Value;
enableStopPropagation = (bool)attribute.ConstructorArguments[3].Value;

In EventHandlerTagHelperDescriptorProvider, the constructor arguments of the EventHandlerAttribute are accessed in the wrong order. The variable enablePreventDefault is being assigned the argument with index 2, when that actually is the enableStopPropagation parameter; the same goes for the enableStopPropagation variable being assigned the argument with index 3.

As far as I can see, this is the only place that accesses the values of these constructor arguments or the properties they are assigned to.

Metadata

Metadata

Assignees

Labels

area-compilerUmbrella for all compiler issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions