fsbolero / Bolero

Bolero brings Blazor to F# developers with an easy to use Model-View-Update architecture, HTML combinators, hot reloaded templates, type-safe endpoints, advanced routing and remoting capabilities, and more.
https://fsbolero.io
Apache License 2.0
1.06k stars 54 forks source link

Server-side prerendering #58

Open Tarmil opened 5 years ago

Tarmil commented 5 years ago

Blazor supports server-side prerendering, for example: https://github.com/danroth27/ClientSideBlazorWithPrerendering. It assumes a Razor-based server side, so there should be a bit of plumbing to get it working from F#.

OnurGumus commented 5 years ago

@Tarmil is this not working already?

Tarmil commented 5 years ago

Yes, now that the server side uses Razor, this is supported. It could use some documentation though 😄

OnurGumus commented 5 years ago

@Tarmil I think we still have a problem. I am still working on that pizza workshop. I use client side + prerendering. What happens is , the links are prerendered, but pizza specials content is fetched via WASM. I am kinda confused.

Tarmil commented 5 years ago

How are the pizza specials retrieved? Via a remote function called from the update? If so, then yeah it's expected that they'll be retrieved from the client.

What you would need to do is call the remote during initialization, because that is run by the prerender. Unfortunately that is currently not possible with the synchronous Program, but with a hypothetical asynchronous AsyncProgram, you could do something like the following:

override this.AsyncProgram = async {
    let remote = this.Remote<PizzaApi>()
    let! specials = remote.GetSpecials()
    return Program.mkProgram (initModel specials) (update remote) view
}

This would call GetSpecials from the server-side prerender, which would allow it to populate the initial HTML correctly. Since this is a server-side call, it is done locally.

Unfortunately the client side would then need to call it again, this time as a proper remote. But at least the full content would be displayed during loading.

srid commented 3 years ago

@Tarmil Is that hypothetical async program currently possible in Bolero (albeit with the shortcoming of the client doing a duplicate request/rendering)?