I need to ask a really lame SSR question. I am run...
# kilua
p
I need to ask a really lame SSR question. I am running the SSR example code in the kilua repo. I created the ssr.zip file and put it in /resources. I added some println stmts to the SSR code. I can see node.js executing the println stmts on the server. However, I do not see the SSR content embedded in the initial html doc. Instead, I see only the "root" div in the html doc and the println() output is appearing in the browser console. I am either misunderstanding the way SSR works, or I am missing something in my SSR setup. Any help would be appreciated.
r
Why do you build your app manually?
You should use kilua plugin tasks, which bundle everything together.
e.g. to build an example from the repo just call
./gradlew :examples:ssr-ktor:jarWithWasmJs
p
Okay, that sounds good. When I used jvmRun and jsBrowserDevelopmentRun, I got a warning that no SSR was found.
r
SSR is only running in production builds
When running dev mode the SSR is not active (and the warning is expected)
p
Ah
r
For ssr to work, the jvm server must actually be called, and that's not possible in dev, because in this mode all request are handled by the webpack dev server.
So you just develop the application like normal app.
Also the real SSR application is built with different webpack configuration. E.g. almost all CSS files are removed from JS/wasmJS code, because the processed CSS (from all modules) is embedded directly into html file generated on the server.
p
Okay, I got it. Amazing stuff Robert! Thanks so much.
One last question. With this code:
Copy code
ssrRouter {
        route("/") {
          println("Root page a: ${isDom}")
          view {
            println("Root page b: ${isDom}")
            template {
              div {
                +"Root page2"
              }
              navLink("/about", "Go to About page")
              navLink("/page${Random.nextInt()}", "Go to random page")
            }
          }
        }
With SSR, I would expect to see the printlns on my server, but I would not expect to see them on my browser console. I am getting the right SSR content in the initial response, but I also see the printlns in the browser console.
r
It's the same code. It runs both on the server and in the browser.
It just do different things.
p
Okay, I just wanted to get it straight in my head. Thanks.
r
In the browser it is mapped to the normal client side routing.
Your app is still SPA and all defined routings work as expected by recomposing the view.
p
Got it. Thanks!
Your explanation is proven by timestamps in the content.
Cool stuff.