-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turbo does not work with Declarative Shadow DOM #1292
Comments
This seems to work as a sort of "polyfill" function fixDSD (e) {
const newElement = e.detail.newBody || e.detail.newFrame || e.detail.newStream
if (!newElement) { return }
// https://developer.chrome.com/docs/css-ui/declarative-shadow-dom#polyfill
;(function attachShadowRoots(root) {
root.querySelectorAll("template[shadowrootmode]").forEach(template => {
const mode = template.getAttribute("shadowrootmode");
const shadowRoot = template.parentNode.attachShadow({ mode });
shadowRoot.appendChild(template.content);
template.remove();
attachShadowRoots(shadowRoot);
});
})(newElement);
}
;["turbo:before-render", "turbo:before-stream-render", "turbo:before-frame-render"].forEach((eventName) => {
document.addEventListener(eventName, fixDSD)
}) |
Thanks for the "polyfill" @KonnorRogers . This is really helpful. In the meanwhile, this issue seems still open, even in the latest version. |
Note that this is very likely due to how "conventional" methods of changing the DOM do not create declarative shadow roots. For this to work, rendering would need to use setHTMLUnsafe or parseHTMLUnsafe. Maybe it's possible to hook into Turbo (https://turbo.hotwired.dev/handbook/drive#custom-rendering) and use these to make DSD elements work? For reference see: |
Turbo appears to leave template tags in place on navigation breaking components that use Declarative Shadow DOM.
2024-07-29.12-35-13.mp4
Reproduction: https://github.com/KonnorRogers/turbo-dsd-reproduction
The text was updated successfully, but these errors were encountered: