Using declarative Shadow DOM #781
Replies: 9 comments 9 replies
-
thats amazing. thanks for this. |
Beta Was this translation helpful? Give feedback.
-
My understanding is that this would already be possible with templ? |
Beta Was this translation helpful? Give feedback.
-
I think I'm struggling here to see what templ would need to add for it to support this? |
Beta Was this translation helpful? Give feedback.
-
I agree that tempo does not need to chance to support it. I have a question about the way that the out of order updates are sent to the browser though . To update the browser it seems that it’s a forever http call to the server with the server flushing to force the client to update . This is so you don’t need any js or htmx . It pretty neat, but it means that the server will be overloaded with a continuous connection that lasts for ever ? Is this what is termed long polling ? |
Beta Was this translation helpful? Give feedback.
-
I think one can create this with templ in it's current form with some manual declarion of the shadow dom and some Go channels. For people to use it that way they would need to have deeper knowledge of how this works. Replacing @Hello(person.Name) with this ?@Hello(person.Name) could make the rendering of the Hello fragment as a shadow dom node and the the decoupling of the rendering with Go channels and push make this much easier. The challenge I think is how to get the connection flushing without coupling to http. |
Beta Was this translation helpful? Give feedback.
-
This is really cool @a-h Thank you for all the work you put into this and working out how to support Flush. I was also wondering about the best way to do this. I am really intrigued with this at the moment, because of the Out of Order nature of this. It may have some nice design advantages with sub systems where the order of changes is non deterministic. Here is a working golang example that uses standard golang templates: https://github.com/ryoid/go-streaming-html-ooo. It is an exact copy of the demo that started this Issue: https://ooo.lamplightdev.workers.dev/ Perhaps we can make the templ equivalent of this as a nice demo. |
Beta Was this translation helpful? Give feedback.
-
This looks fantastic - thanks @gedw99 I had the same thought when I saw that demo in r/golang. I think @flush is the better way, it doesn't change the syntax as my idea did. Do you think Slot middleware should be in templ or a templ-middleware package? |
Beta Was this translation helpful? Give feedback.
-
In the next version of templ, you'll be able to use Declarative Shadow DOM to defer loading of content without JavaScript on the client side. See PR #802 The PR adds two new examples - one that demonstrates basic flushing, and another that uses Declarative Shadow DOM to defer loading with placeholders (suspense) without JavaScript. Just some documentation required on how streaming mode affects your ability to set the HTTP header one the body has started to be sent to the client, and an explanation of the examples is required now. Thanks for the nudge to do this. There was discussion of streaming responses, but I didn't really see the value. The Declarative Shadow DOM is worth it. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Browsers now (or in the near future) support declarative Shadow DOM.
https://caniuse.com/declarative-shadow-dom
You can then render
<slot name="content"></slot>
, stream this to the client, then later stream<div slot="content">Rendered with content</div>
and the browser will replace the slot with the new content without the need for Javascript.The content could come from a Go channel e.g. reading from a database, and the page could still be sent (header, footer, nav) with the data replacing the placeholder as soon as the channel delivers results.
AJAX without Javascript for a faster Time to First Byte (TTFB).
For a demo see https://ooo.lamplightdev.workers.dev/
It's like Metas BigPipe (2010) but without Javascript
https://engineering.fb.com/2010/06/04/web/bigpipe-pipelining-web-pages-for-high-performance/
Beta Was this translation helpful? Give feedback.
All reactions