dotnet-websharper / ui

A reactive UI library for WebSharper.
https://websharper-samples.github.io/ui/
Apache License 2.0
77 stars 22 forks source link

Instatiation of the template doesn't work on client (C#) #189

Closed V0d01ey closed 6 years ago

V0d01ey commented 6 years ago

When trying to instantiate a html-template in a new client-server application (from the project template) WS doesn't find it writing this line to console:

Local template doesn't exist null WebSharper.UI.js:5817

Html-file containing only a form is named:

UploadDialogTemplate.html

It's generated cs-file is:

UploadDialogTemplate.g.cs

And class is named:

Uploaddialogtemplate

WS seeks for key uploaddialogtemplate.

    [JavaScript]
    public static class Client
    {
        static public IControlBody Main()
        {
            var rvInput = Var.Create("");
            var submit = Submitter.CreateOption(rvInput.View);
            var vReversed =
                submit.View.MapAsync(input =>
                {
                    if (input == null)
                        return Task.FromResult("");
                    return Remoting.DoSomething(input.Value);
                });
            return div(
                input(rvInput),
                button("Send", submit.Trigger),
                hr(),
                h4(
                    attr.@class("text-muted"),
                    "The server responded:",
                    div(
                        attr.@class("jumbotron"),
                        h1(vReversed)
                    )
                ),
                new Template.Uploaddialogtemplate().Doc()   // <--  this line was added
            );
        }
    }

PS. Also, it would be great if generated cs-file was automatically included to c#-project.

Tarmil commented 6 years ago

What's happening here is that the templating system is trying to load the template contents from the DOM, assuming that the template corresponds to the current HTML document, instead of embedding it in the compiled javascript.

The cause is a really silly bug that I'll fix immediately: arguments aren't passed along correctly here.

Until this fix is released you can override this by adding the following to the top of your HTML file:

<!-- ClientLoad = Inline -->

PS. Also, it would be great if generated cs-file was automatically included to c#-project.

I'm not certain the Roslyn analyzer API allows this kind of modification. @Jand42 you know much more than me about Roslyn, is this possible? It would be nice.

V0d01ey commented 6 years ago

@Tarmil , the problem was not solved.

Tarmil commented 6 years ago

Oh right sorry for the confusion indeed. For a template that is not used as the served index file, the comment is mandatory:

<!-- ClientLoad = Inline -->