diff --git a/.changeset/eighty-tools-search.md b/.changeset/eighty-tools-search.md new file mode 100644 index 00000000..7bc3abbd --- /dev/null +++ b/.changeset/eighty-tools-search.md @@ -0,0 +1,5 @@ +--- +"preact-render-to-string": patch +--- + +fix: hydration might remove the node from the DOM causing it no longer have a parent diff --git a/src/lib/client.js b/src/lib/client.js index c0f5cb72..b2325626 100644 --- a/src/lib/client.js +++ b/src/lib/client.js @@ -36,7 +36,7 @@ // c = s; // } -// d.parentNode.removeChild(d); +// if (d.parentNode) d.parentNode.removeChild(d); // }); // } // } @@ -46,7 +46,7 @@ // } // To modify the INIT_SCRIPT, uncomment the above code, modify it, and paste it into https://try.terser.org/. -const INIT_SCRIPT = `class e extends HTMLElement{connectedCallback(){var e=this;if(!e.isConnected)return;let t=this.getAttribute("data-target");if(t){for(var r,a,i=document.createNodeIterator(document,128);i.nextNode();){let e=i.referenceNode;if(e.data=="preact-island:"+t?r=e:e.data=="/preact-island:"+t&&(a=e),r&&a)break}r&&a&&requestAnimationFrame((()=>{for(var t=a.previousSibling;t!=r&&t&&t!=r;)a.parentNode.removeChild(t),t=a.previousSibling;for(i=r;e.firstChild;)r=e.firstChild,e.removeChild(r),i.after(r),i=r;e.parentNode.removeChild(e)}))}}}customElements.define("preact-island",e);`; +const INIT_SCRIPT = `class e extends HTMLElement{connectedCallback(){var e=this;if(!e.isConnected)return;let t=this.getAttribute("data-target");if(t){for(var r,a,i=document.createNodeIterator(document,128);i.nextNode();){let e=i.referenceNode;if(e.data=="preact-island:"+t?r=e:e.data=="/preact-island:"+t&&(a=e),r&&a)break}r&&a&&requestAnimationFrame((()=>{for(var t=a.previousSibling;t!=r&&t&&t!=r;)a.parentNode.removeChild(t),t=a.previousSibling;for(i=r;e.firstChild;)r=e.firstChild,e.removeChild(r),i.after(r),i=r;e.parentNode&&e.parentNode.removeChild(e)}))}}}customElements.define("preact-island",e);`; export function createInitScript() { return ``;