Skip to content

Commit c63f25d

Browse files
fix(runtime): check shadow root nodes before appending them (#6342)
1 parent 188e7db commit c63f25d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/runtime/client-hydrate.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,17 @@ export const initializeClientHydrate = (
279279
const rnLen = shadowRootNodes.length;
280280
if (rnLen) {
281281
for (rnIdex; rnIdex < rnLen; rnIdex++) {
282-
shadowRoot.appendChild(shadowRootNodes[rnIdex]);
282+
const node = shadowRootNodes[rnIdex];
283+
284+
/**
285+
* in apps with a lot of components the `shadowRootNodes` array can be modified while iterating over it
286+
* so we need to check if the node is still in the array before appending it to avoid any errors like:
287+
*
288+
* TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
289+
*/
290+
if (node) {
291+
shadowRoot.appendChild(node);
292+
}
283293
}
284294

285295
Array.from(hostElm.childNodes).forEach((node) => {

0 commit comments

Comments
 (0)