S
SolidJS5mo ago
Helge

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
<html>
<body>
<h1>this is a headline</h1>
<p>some para text</p>
<div data-component="features"></div>
<p>some more text</p>
</body>
</html>
<html>
<body>
<h1>this is a headline</h1>
<p>some para text</p>
<div data-component="features"></div>
<p>some more text</p>
</body>
</html>
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
thetarnav
thetarnav5mo ago
looks like you already know what to do some html parser and a bunch of <Dynamic> components to put it together again
Helge
Helge5mo ago
But 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
thetarnav
thetarnav5mo ago
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
Helge
Helge5mo ago
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
thetarnav
thetarnav5mo ago
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 at
Helge
Helge5mo ago
oh is that so?
Want results from more Discord servers?
Add your server
More Posts
How to trigger createEffect when navigating to the same URL ?Hi, is it possible to trigger a createEffect that listens to location.search from the solid router'sGetting ReferenceError: React is not defined with Vitest + Solid Testing LibraryI honestly have no idea how I am receiving this error but I am despite testing using `@solidjs/testibackend solidstart or another backend.Does solidstart make sense if a third-party backend (fastapi) is used? I don't want to write backendUnderstanding the deployment of a SolidJS app (with a separate backend)I hope this doesn’t go too off topic because this is more of a general question but I am trying to uCreating custom SolidJS hook that can be used in a global scopeNeed some help understanding how to build a custom SolidJS hook that can be used both locally insideHow to set a cookie that is returned from api call?I'm using createAsync for a server api call. The api returns data with cookie that I need later. ```renderToString not workI have two questions about SSR: 1. It cannot work according to document about renderToString. The bruseNavigate wrapped in <Router>Hello! I'm trying to use useNavigate inside a top-level element so I can setup some event listeners Response.clone: Body has already been consumed. Seroval/trpc conflict?There was some discussion about this recently, but was there a way to fix this currently in user codSolidStart for PWA with CSR? And Guide of available templates.I want to build a PWA with **CSR**. So, I've installed Solid Start, and used the "basic" template.