Bolero icon indicating copy to clipboard operation
Bolero copied to clipboard

Server-side prerendering

Open Tarmil opened this issue 5 years ago • 5 comments

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#.

Tarmil avatar Jun 20 '19 15:06 Tarmil

@Tarmil is this not working already?

OnurGumus avatar Nov 15 '19 17:11 OnurGumus

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

Tarmil avatar Nov 15 '19 18:11 Tarmil

@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.

OnurGumus avatar Nov 16 '19 02:11 OnurGumus

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.

Tarmil avatar Nov 17 '19 10:11 Tarmil

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

srid avatar Mar 24 '21 20:03 srid