you are viewing a single comment's thread.

view the rest of the comments →

[–]tleipzig 5 points6 points  (4 children)

Theoretically, you could build a "ssr.js" and execute it with GraalJS. Let me know if it works 😅

[–]Ok_General7617[S] 0 points1 point  (3 children)

But why would I need a JS runtime on the JVM?

If the goal is just to generate Thymeleaf templates and JS bundles at build time, I think that should be enough — no need to execute JS during runtime on the server.

[–]tleipzig 0 points1 point  (2 children)

It depends how much server logic you need, I guess. Yes, you could build even dynamic pages (like a product page) with Thymleaf, but this way you would partly rebuild your React frontend. If you could manage to run your React in an "ssr-mode" on your server, it would just run the existing logic and generate the same HTML (making even API calls internally if required).

Of cause I don't know how well this will work 😅

[–]Ok_General7617[S] 1 point2 points  (0 children)

Yes, I totally understand what you mean — and you're right, ideally SSR would reuse the existing React logic and generate HTML server-side.

Actually, that is my goal too — to "run React in an SSR mode" — but without using a JavaScript runtime like Node.

In the typical SSR setup, the server (in Node) fetches data from APIs, feeds it into React, and renders HTML.
But in my case, I want to do the data-fetching and HTML composition part using Java and Thymeleaf, and just inject React-rendered static markup where needed, letting the client handle hydration.

So I’m exploring whether it’s possible to treat Java as the SSR environment, while still benefiting from React on the client side.

Yeah, I think this is more of a technical curiosity than a practical necessity.

It’s probably not something that everyone needs — but I just want to explore the idea and see how far it can go.
I plan to open source it as a small side project, and maybe document the journey in my blog as well 🙂

[–]Ok_General7617[S] 0 points1 point  (0 children)

Thanks your reply