-
Notifications
You must be signed in to change notification settings - Fork 9
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
expand (no-op) support of DOM shim for DOM traversal methods #37
Comments
This comment seems to be relevant for
|
It seems at least somewhat trivial to at least support no-ops for some of the basic DOM querying methods though? For example, being able to do something like this with import sheet from './hero.css' with { type: "css" };
const template = '...';
export default class HeroBanner extends HTMLElement {
clickButton(el) {
console.log('clicked button =>', el.textContent);
}
connectedCallback() {
if (!this.shadowRoot) {
this.attachShadow({ mode: 'open' });
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
this.shadowRoot.adoptedStyleSheets = [sheet];
this.shadowRoot.querySelectorAll('button')
.forEach(button => {
button.addEventListener('click', () => this.clickButton(button))
});
}
}
customElements.define('app-hero', HeroBanner); What else does a ShadowRoot support? 🤔 |
One simple trick that could be worth documenting, is to completely opt-out of SSR / prerendering (at least in Greenwood) is to use the good ol' import copy from "../../assets/copy-button.svg?type=raw";
import sheet from "./copy-to-clipboard.css" with { type: "css" };
const template = document.createElement("template");
template.innerHTML = `
<button id="icon" title="Copy to clipboard">${copy}</button>
`;
export default class CopyToClipboard extends HTMLElement {
connectedCallback() {
// bail of out of SSR entirely
if (!this.shadowRoot && typeof window !== "undefined") {
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(template.content.cloneNode(true));
this.shadowRoot.adoptedStyleSheets = [sheet];
this.shadowRoot.getElementById("icon")?.addEventListener("click", () => {
const contents = this.getAttribute("content") ?? undefined;
navigator.clipboard.writeText(contents);
console.log("copying the following contents to your clipboard =>", contents);
});
}
}
}
customElements.define("app-ctc", CopyToClipboard); |
Type of Change
Summary
Tracking a number of items that I think the DOM shim should be able to support, though I'm not sure how feasible / realistic any of them are, so will need to do some discovery of what makes sense to fall "in bounds" for SSR, short of just becoming a headless browser.
Details
Not sure how many of these can / should be supported, but some of them at least, if not at least for no-ops
querySelector
/querySelectorAll
getElementBy[Id|ClassName|TagName|...]
Questions
appendNode
implemented correctly?The text was updated successfully, but these errors were encountered: