riot / ssr

Riot.js node Server Side Rendering
MIT License
32 stars 8 forks source link

Suggestion: Separate render and mount logic #12

Closed cybervaldez closed 4 years ago

cybervaldez commented 4 years ago

I'm using webpack to generate the static files for my ssr renders but i'm getting a lot of errors due to how my logic are in the mount. A solution I have is to check if it's running in a node environment or not:

onMounted(){
if(typeof module === 'undefined' || !module.exports){
// animate header
}
}

another solution is to use onHydrated but that also have issues because of nested components. Perhaps a more elegant solution to this is to have an onRender method?

cybervaldez commented 4 years ago

After some playing around with, passing a ssr parameter makes it more flexible.

let html = render('app', App, { menu, ssr : true });

this also makes it possible to hide certain tags from showing up in the rendered html.