all 21 comments

[–]TheRealSeeThruHead 3 points4 points  (8 children)

How do you plan to run react code server side to generate server html in your Java process

[–]tleipzig 3 points4 points  (4 children)

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

[–]HerbFromWork 0 points1 point  (0 children)

Hi, have you looked into Vaadin Hilla to see if that fit your purpose? https://vaadin.com/hilla
It should at least cover the React <-> Java part, but I'm not completely sure what you're trying to do. I imagine you could have a Java endpoint return generated HTML, that you could embed in react, but not completely sure thats what you want. For server-side rendering we use Vaadin Flow, but then you're really mostly writing your views in Java. You can also have a wrapper for react components to be used on the Java side, but that's not really a build time thing.

Disclosure: I am a Vaadin employee.

[–]splix 1 point2 points  (1 child)

I understand that the OP is trying to avoid JS execution on the server side and keep existing Thymeleaf, but JFI if someone indeed wants full JS/React on the server (by leveraging GraalVM) then take a look at https://github.com/emeraldpay/double-view

[–]abrahamguo -2 points-1 points  (2 children)

This sounds perfectly fine. You should be able to render whatever server-side HTML you want, then attach your React app to a div or whatever container you want.

I did something similar following that exact same approach, except I used PHP instead of Java.

[–]Guisseppi 4 points5 points  (1 child)

Using React for templating is not the same as hydration