Use solid as middleware
Goal: parse existing html from third party server, read all data-component attributes from HTML, load dynamic component based on data-component attribute and then return newly rendered HTML w/ interactivity.
Hi I would like to create a Solid-Middleware so to speak. I want to parse a given HTML and look for tells to load components dynamically and then return it all to the browser. How would you start doing this?
The following markup would be for example fetched dynamically based on given slug
The goal is to parse, load
features.tsx
, render it on the server and also make it so that it can be used with interacitivty on the client
Any advice is welcome.6 Replies
looks like you already know what to do
some html parser
and a bunch of
<Dynamic>
components to put it together againBut can I leverage Solid Start for that @thetarnav ?
and how would you gobble the given html together ? I was initially thinking about a replace w/ jsdom transform, back to html and then pass it to the html``-tagged template but you cannot pass down a string like that from a var i think,.. atleast I didnt figure out how to
tagged templates don’t support ssr anyway
you could to have the server and client setup for ssr
but it won’t help with parsing html part
the naive solution would be to do some jsdom transform and then children.forEach(child => <Dynamic as={child.tagName} />)
with some branching of switch(node.dataset.component){}
but that feels wrong to me, there must be a cleaner way ? template() is nice but only works on client as well so Ideally I would have a ssrTempalte(html-string) as root that would then handle all
I’m not sure if it’s naive
that’s what site builders like builder.io do with solid
but since you only have few places with a component, and the rest is static html
there should be a different way too
on the server you can use
renderToString
for the dynamic components
and concatenate to have the html response
on the client those components need to be hydrated to be interactive
the astro adapter might be worth looking atoh is that so?