solidjs / solid-meta

Write meta tags to the document head
127 stars 16 forks source link

SSR with renderTags() #29

Open gxxcastillo opened 1 year ago

gxxcastillo commented 1 year ago

I'm using renderToStream() for SSR but renderTags() returns a string which ends up getting escaped. Is there a way to have something like renderTags() but have it return JSX?

KevinBLT commented 1 year ago

I need the same

ryansolid commented 1 year ago

The problem is how it gets inserted. Returning JSX doesn't really work for us because JSX doesn't really exist for us at runtime. So the way to insert it is either directly in the HTML string if you have it top level or, if inserting in Solid's JSX wrap it in an ssr call. It basically treats it like an already escaped template.

This is exported from solid-js/web. So you probably want to run this code in server only context (ie guarded by isServer or eqivalent). That being said the tags aren't there until the server finishes rendering so to make it work in the JSX you probably need to use something likeuseAssetsfromsolid-js/web` anyway. Which is why I didn't expect to see this issue as none of these APIs are documented so I figured most people would just be inserting their markup in an HTML string at the end where you wouldn't have to worry about escaping.

In any case I hope these hints help. SolidStart is also a good reference here.