From 54cbd164a8ba493fdb10d53ec80b69e42428f871 Mon Sep 17 00:00:00 2001 From: Kyle Robinson Young Date: Thu, 24 Aug 2023 13:31:54 -0700 Subject: [PATCH] fix: ensure child node is a child of parent before removing Fixes GH-1401 If `current` isn't a child of `parent` calling `parent.removeChild(current)` will result in the error: `Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node`. This commonly occurs when the DOM is externally modified by a browser, such as when translating a page. The `nextSibling` may not be a child node of `parent`. `current.parentNode?.removeChild(current)` ensures we are only removing a child node of a parent node. --- packages/@glimmer/runtime/lib/bounds.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/@glimmer/runtime/lib/bounds.ts b/packages/@glimmer/runtime/lib/bounds.ts index 93a936bd9..62b44257f 100644 --- a/packages/@glimmer/runtime/lib/bounds.ts +++ b/packages/@glimmer/runtime/lib/bounds.ts @@ -65,7 +65,6 @@ export function move(bounds: Bounds, reference: Nullable): Nullable< } export function clear(bounds: Bounds): Nullable { - let parent = bounds.parentElement(); let first = bounds.firstNode(); let last = bounds.lastNode(); @@ -75,7 +74,7 @@ export function clear(bounds: Bounds): Nullable { while (true) { let next = current.nextSibling; - parent.removeChild(current); + current.parentNode?.removeChild(current); if (current === last) { return next;