devpunks / snuggsi

snuggsi ツ - Easy Custom Elements in ~1kB
https://snuggsi.com
MIT License
395 stars 17 forks source link

Server side rendering #226

Closed eldoy closed 1 year ago

eldoy commented 1 year ago

How do I do server side rendering?

snuggs commented 1 year ago

@eldoy great question! didn't really think about it as just using in the browser is so fast. However i'm sure an implementation can be done. The rendering algorithm is like 20LOC. Thoughts? Examples?

eldoy commented 1 year ago

@snuggs There is no need for this library (or any other library really) when you can just use JS functions that returns template strings:

function link({ url, text }) {
  return `<my-link><a href="${url}">${text}</a></my-link>`
}

This works both on server and browser (isomorphic even) with 0 (zero) dependencies. Is it worth spending time on creating something that is inferior to what is already working perfectly just for some syntactic sugar?

snuggs commented 1 year ago

Interesting...probably just need some sort of "node parser". Under the hood we use the sparsely documented TreeWalker. What is an advantage is whatever other libraries are using to SSR can guarantee it is orders of magnitude more complex. We just use TreeWalker. Wonder if there is anything lighter than JSDOM. Or whatever others are doing. Custom Elements ARE bonified DOM elements. Just thinking out loud.