fix: <Suspense> boundaries with no ctx.style (#68)

This commit is contained in:
Luca Casonato
2021-10-04 11:58:01 +02:00
committed by GitHub
parent f343e8bac7
commit d1076b0ad1
2 changed files with 7 additions and 6 deletions
+6 -4
View File
@@ -17,10 +17,12 @@
/** @type {HTMLStyleElement} */
const sheetElement = document.getElementById("__FRSH_STYLE");
const rules = sheetElement.childNodes[0].textContent.split(`\n`);
sheetElement.removeChild(sheetElement.firstChild);
for (const rule of rules) {
sheetElement.append(document.createTextNode(rule));
const rules = sheetElement.childNodes[0]?.textContent.split("\n");
if (rules !== undefined) {
sheetElement.removeChild(sheetElement.firstChild);
for (const rule of rules) {
sheetElement.append(document.createTextNode(rule));
}
}
/** Insert new style rules. */
window.$ST = (inserts) => {
+1 -2
View File
@@ -191,8 +191,7 @@ export async function* render(opts: RenderOptions): AsyncIterable<string> {
if (suspenseQueue.length > 0) {
// minified client-side JS
yield `<script>(()=>{window.$SR=(e=>{const t=document.getElementById("S:"+e),o=document.getElementById("E:"+e),d=document.getElementById("R:"+e);for(d.parentNode.removeChild(d);t.nextSibling!==o;)t.parentNode.removeChild(t.nextSibling);for(;d.firstChild;)t.parentNode.insertBefore(d.firstChild,o);t.parentNode.removeChild(t),o.parentNode.removeChild(o)});const e=document.getElementById("__FRSH_STYLE"),t=e.childNodes[0].textContent.split("\n");e.removeChild(e.firstChild);for(const o of t)e.append(document.createTextNode(o));window.$ST=(t=>{for(const[o,d]of t)e.insertBefore(document.createTextNode(o),e.childNodes[d])})})();</script>`
.replaceAll("\n", "\\n");
yield '<script>(()=>{window.$SR=t=>{const e=document.getElementById("S:"+t),o=document.getElementById("E:"+t),d=document.getElementById("R:"+t);for(d.parentNode.removeChild(d);e.nextSibling!==o;)e.parentNode.removeChild(e.nextSibling);for(;d.firstChild;)e.parentNode.insertBefore(d.firstChild,o);e.parentNode.removeChild(e),o.parentNode.removeChild(o)};const n=document.getElementById("__FRSH_STYLE"),r=n.childNodes[0]?.textContent.split(`\n`);if(r!==void 0){n.removeChild(n.firstChild);for(const t of r)n.append(document.createTextNode(t))}window.$ST=t=>{for(const[e,o]of t)n.insertBefore(document.createTextNode(e),n.childNodes[o])}})();\n</script>';
}
// TODO(lucacasonato): parallelize this