dom-expressions
dom-expressions copied to clipboard
`useAssets` is currently no-op in SSR if the markup doesn't have a `<head>`
useAssets
relies on <head>
to inject its markup, which feels off where in some cases some users would just render from the an specific root instead of the whole document, which also applies to Islands.
It would be helpful if useAssets
doesn't rely on such mechanism. For instance, in my JSX library, stellis
, I run the following checks:
- if the resulting markup is an HTML markup
- if the markup has a head
- Match the opening head element and insert pre-
<head>
content - Match the closing head element and insert post-
<head>
content
- Match the opening head element and insert pre-
- if the markup has no head
- Concat both pre and post
<head
content and wrap it in a<head>
markup then insert it before the HTML opening element.
- Concat both pre and post
- if the markup has a body
- Match the opening body element and insert pre-
<body>
content - Match the closing body element and insert post-
<body>
content
- Match the opening body element and insert pre-
- if the markup has no body
- Create a
<body>
opening, append the pre-<body>
content and insert it after</head>
- Create a
<body>
closing, prepend the post-<body>
content and insert it before</html>
- Create a
- if the markup has a head
- if the resulting markup isn't an HTML markup (partial render)
- if the markup has a body
- Match the opening body element and insert pre-
<body>
content - Match the closing body element and insert post-
<body>
content
- Match the opening body element and insert pre-
- if the markup has no body
- if the markup has no head
- Insert the pre and post
<body>
content on both ends of the markup
- Insert the pre and post
- if the markup has no head
- if the markup has a head
- Match the opening head element and insert pre-
<head>
content - if the markup has no body
- Match the closing head element and insert post-
<head>
and pre-<body>
content - Append post-
<body>
content to the markup
- Match the closing head element and insert post-
- Match the opening head element and insert pre-
- if the markup has no head
- Prepend both pre and post
<head>
content to the markup
- Prepend both pre and post
- if the markup has a body
Here's the implementation: https://github.com/lxsmnsyc/stellis/blob/main/packages/stellis/src/index.ts#L163-L231
I would love to know what you think about this