core
core copied to clipboard
Local functions escape in event handlers on server-side templates
Event handlers in server-side templates are automatically translated for client-side use, however, local functions in those handlers escape without raising an error. Consider the following code:
let elem =
let foo (a: int) = a+12
MyTemplateWithASaveButton()
.Save(fun e ->
Console.Log <| foo 10
)
Here, the generated code will have the call foo(10), with foo being undefined. The expected behavior would be to raise an error on calling a non-JS annotated function.
Note that other free variables that represent non-function values are correctly handled: their values are passed to the generated event handlers. For instance:
<button onclick="WebSharper.UI.Templating.Runtime.Server.Handler.EventQ2$189$36("578cac9a-8453-49bd-a3a6-005a3004834c",Site.ManagedContent$108$22(123,"value1","value2"))(this)(event)">Save</button>