Sunil Kumar
06/28/2025, 5:42 AMThis router will defer the rendering on the server until some asynchronous
* operation (e.g. fetching data) is finished.
If we use SimpleSsrRouter even when fetching data, then what impact it will have?
This router can be used to directly declare UI components for each route,
* which will be rendered on the server immediately for every request.
I understood their definitions, but can u tell us what exactly are theses differences, when they do make sense and when we should use each one?
Does it means, if we are fetching some async data, then we should prefer AsyncSsrRouter else SimpleSsrRouterRobert Jaros
06/28/2025, 7:46 AMRobert Jaros
06/28/2025, 7:52 AMSimpleSsrRouter
is ... simple. It can be used for some very basic applications, which don't need any external data sources. Just like these simple ssr apps in the project's examples directory. See here: https://github.com/rjaros/kilua/blob/main/examples/ssr-javalin/src/webMain/kotlin/example/main.kt#L43-L72Robert Jaros
06/28/2025, 7:55 AMBrowserRouter
with SimpleSsrRouter
without any code changes.Robert Jaros
06/28/2025, 7:56 AMAsyncSsrRouter
.Robert Jaros
06/28/2025, 8:06 AM/article/15
url to display the content of article number 15. When you are on the client side, it's easy - your app is already loaded, when the url is triggered by user navigation, you probably show some progress bar, fetch the data from the server, change the state in some store and then render the correct article content.
But when the same url is send to the server you would like the SSR engine to return html page with the same, correct article content. You need to let the server know, when the content is ready to be returned. And that's the work of AsyncSsrRouter
. You also use "state based routing" (https://kilua.gitbook.io/kilua-guide/2.-frontend-development-guide/routing#layout-based-routing-vs.-state-based-routing) for this (routeAction
instead of route
).Robert Jaros
06/28/2025, 8:07 AMRobert Jaros
06/28/2025, 8:16 AMrouteAction
(or other *Action
functions) is suspending and should return only then the whole data fetching process is ready. You should make all the actions I've mentioned previously inside this lambda call (e.g. show progress, fetch data, update state, hide progress). The same code is used on the client side so it will work correctly as well. And on the server side it will wait until data is ready before rendering the composition to html file content.Sunil Kumar
06/28/2025, 10:17 AM