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.
Summary
The parameters
enableStopPropagationandenablePreventDefaultof the EventHandlerAttribute are swapped by the razor compiler, so that settingenableStopPropagation = trueactually enablespreventDefault, 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:
When I set
@ontransitionend=SomeCallbackon 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:stopPropagationon 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:preventDefaultis 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
razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/EventHandlerTagHelperDescriptorProvider.cs
Lines 74 to 75 in 056b3be
In EventHandlerTagHelperDescriptorProvider, the constructor arguments of the EventHandlerAttribute are accessed in the wrong order. The variable
enablePreventDefaultis being assigned the argument with index 2, when that actually is theenableStopPropagationparameter; the same goes for theenableStopPropagationvariable 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.