core icon indicating copy to clipboard operation
core copied to clipboard

Local functions escape in event handlers on server-side templates

Open granicz opened this issue 4 years ago • 1 comments

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.

granicz avatar Oct 13 '21 00:10 granicz

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>

granicz avatar Oct 13 '21 01:10 granicz