Closed Andrzej-W closed 5 years ago
@Andrzej-W Thanks for contacting us.
I don't see any reason why It wouldn't be supported, but keep in mind that we will be focusing on client-side Blazor in the following months and as a result things might change.
As per your scenario specifically there are alternative ways of achieving the same result, that might be better suited than retrieving the rendered markup on first run. I believe there are some community projects around this already.
@danroth27 Can you recommend an existing community solution for this?
We understand your concerns, @Andrzej-W. As @javiercn has mentioned, there are no current plans to drop support for calling JavaScript from Blazor synchronously. Will our plans change in the future or not - don't know. We'll know more as we'll get further along with Blazor WASM release.
Unfortunately #14836 was moved to backlog. To implement prerendering without screen flickering I have found a solution in my own application without any framework modification. Unfortunately to implement this correctly I have to call one JavaScript function synchronously. To do this I need to cast IJSRuntime to IJSInProcessRuntime. Of course I use it only when my application works in the browser.
Prerendering without screen flickering on pages which load some data dynamically is a must have feature in my application. Before I spend more time on further work, I would like to ask if in future versions of Blazor Wasm we will always have the option to call JavaScript functions synchronously.
@SteveSandersonMS Probably about a year ago you wrote there are some plans to move Blazor to web worker. Is it possible that after this change we will have to make all JavaScript calls asynchronously?
To implement my "perfect prerendering without flickering" I have to make a single synchronous JS call, otherwise component is rendered with "Loading..." message. Here is an example
If you want to see the final effect open this app http://hpsspa.azurewebsites.net/fetchdata and press F5 to refresh it a few times. Notice there is no screen flickering. Page is displayed very fast (it is prerendered and cached on the server for 60 seconds). The application starts and new random forecast is loaded, but you don't see "Loading..." message on the screen. Instead new forecast replaces the old one in place without flickering. When application is already loaded and you navigate between pages it works as standard (you will see Loading... message, and then table with forecast)
My prototype is based on this example https://github.com/danroth27/BlazorWebAssemblyWithPrerendering created by @danroth27 and is available here: https://github.com/Andrzej-W/BlazorWebAssemblyWithPrerendering