Skip to content

Commit 2807f68

Browse files
committed
fix(core): get parent in removeChild from parentNode; do not remove children if oldChild is scene
1 parent 98b5afb commit 2807f68

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Diff for: libs/core/src/lib/renderer/index.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,17 @@ export class NgtRenderer implements Renderer2 {
281281
this.appendChild(parent, newChild);
282282
}
283283

284-
removeChild(parent: NgtRendererNode | null, oldChild: NgtRendererNode, isHostElement?: boolean | undefined): void {
284+
removeChild(
285+
parent: NgtRendererNode | null,
286+
oldChild: NgtRendererNode,
287+
isHostElement?: boolean | undefined,
288+
calledByNgt = false,
289+
): void {
290+
if (!calledByNgt && parent == null) {
291+
parent = this.parentNode(oldChild);
292+
return this.removeChild(parent, oldChild, isHostElement, true);
293+
}
294+
285295
if (parent == null) {
286296
parent = (untracked(() => getLocalState(oldChild)?.parent?.()) ||
287297
oldChild.__ngt_renderer__?.[NgtRendererClassId.parent]) as NgtRendererNode;
@@ -293,13 +303,13 @@ export class NgtRenderer implements Renderer2 {
293303
// we'll just remove the child and destroy it
294304
if (parent == null) {
295305
if (cRS) {
306+
// if the child is the root scene, we don't want to destroy it
307+
if (is.scene(oldChild) && oldChild.name === '__ngt_root_scene__') return;
308+
296309
if (cRS[NgtRendererClassId.type] === 'three') {
297310
removeThreeChild(oldChild, undefined, true);
298311
}
299312

300-
// if the child is the root scene, we don't want to destroy it
301-
if (is.scene(oldChild) && oldChild.name === '__ngt_root_scene__') return;
302-
303313
// otherwise, we'll destroy it
304314
this.destroyInternal(oldChild, undefined);
305315
}

0 commit comments

Comments
 (0)