turbine icon indicating copy to clipboard operation
turbine copied to clipboard

Simple server side rendering

Open paldepind opened this issue 7 years ago • 4 comments

With a way to stringify a component it would be possible to support simple server side rendering.

The API could consist of componentToString and serveComponent. The first would turn a component into a string and the second would return a NodeJS compatible endpoint function.

Example.

app.get("/app", serveComponent("index.html", "body", myComponent));

This would offer a really simple way of getting many of the benefits from server-side rendering with very little effort from end-users.

paldepind avatar Apr 30 '17 17:04 paldepind

I imagine that we can use something like JSDOM to run the component in NodeJS and pre-generate the DOM.

limemloh avatar May 04 '17 12:05 limemloh

@trusktr

That would be awesome to do with Turbine. Maybe we can just run turbine stuff in jsdom, and get the output?

Maybe there could be a way to make Turbine output strings instead of actual DOM elements?

If possible I think turning Components into strings directly is best. If this is something that interests you I can put a simple proof of concept together to illustrate how I imagine it can be implemented.

What do you think about the API I show in the post above?

paldepind avatar May 31 '17 09:05 paldepind

@paldepind I suppose that works. I'm also looking at Vue+Nuxt.js, which abstracts that part away.

trusktr avatar Aug 21 '17 21:08 trusktr

They do it very very declaratively. But so do you!! I think the functional-to-HTML approach you have is nice.

trusktr avatar Aug 27 '17 05:08 trusktr