loreanvictor / rehtm

Create and hydrate HTML with HTM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better SSR Support

loreanvictor opened this issue · comments

One of the main points of rehtm is that it supports SSR. In an SSR-context, it might easily happen that there is no global document object, which is referenced in the following parts in the code:

const node = document.createElement(type)

const child = document.createTextNode(value.toString())

this.template = document.createElement('template')

const target = document.importNode(this.template.content, true)

This should be resolved so that a document object can be provided. I suspect since all of these call sites center around some DOM factory, perhaps a document property can be added to DOMFactory type, bubbling upwards the API so that any user can provide a custom API (falling back to the global document if not provided), potentially adding some generators alongside exported constants, producing something like this in the end:

const { html, template, recipe, cached } = use(document)