Skip to content

Commit 2691fd0

Browse files
committed
fix(core): bail if parent is null in removeChild but do clean up if there's internal child
1 parent 91c51cf commit 2691fd0

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

libs/core/src/lib/renderer/index.ts

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

283-
removeChild(parent: NgtRendererNode, oldChild: NgtRendererNode, isHostElement?: boolean | undefined): void {
283+
removeChild(parent: NgtRendererNode | null, oldChild: NgtRendererNode, isHostElement?: boolean | undefined): void {
284284
if (parent == null) {
285285
parent = (untracked(() => getLocalState(oldChild)?.parent) ||
286286
oldChild.__ngt_renderer__[NgtRendererClassId.parent]) as NgtRendererNode;
@@ -290,9 +290,14 @@ export class NgtRenderer implements Renderer2 {
290290

291291
// if parent is still falsy, we don't know what to do with the parent.
292292
// we'll just remove the child and destroy it
293-
if (parent == null && cRS?.[NgtRendererClassId.type] !== 'three') {
294-
removeThreeChild(oldChild, undefined, true);
295-
this.destroyInternal(oldChild, undefined);
293+
if (parent == null) {
294+
if (cRS) {
295+
if (cRS[NgtRendererClassId.type] === 'three') {
296+
removeThreeChild(oldChild, undefined, true);
297+
}
298+
this.destroyInternal(oldChild, undefined);
299+
}
300+
296301
return;
297302
}
298303

libs/soba/src/misc/decal.stories.ts

+17-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
viewChild,
1212
} from '@angular/core';
1313
import { Meta } from '@storybook/angular';
14-
import { NgtArgs, NgtThreeEvent } from 'angular-three';
14+
import { NgtArgs } from 'angular-three';
1515
import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';
1616
import { NgtsOrbitControls } from 'angular-three-soba/controls';
1717
import { injectTexture } from 'angular-three-soba/loaders';
@@ -62,24 +62,26 @@ class LoopOverInstancedBufferAttribute {
6262
6363
<ngt-directional-light [position]="[1, -1, 1]" [intensity]="Math.PI" />
6464
65-
<ngt-mesh #mesh (click)="onClick($any($event))">
65+
<ngt-mesh #mesh>
6666
<ngt-sphere-geometry *args="[3, 32, 32]" />
6767
<ngt-mesh-physical-material color="tomato" [roughness]="0.5" />
6868
</ngt-mesh>
6969
70-
<decal-loop-over-instanced-buffer-attribute [buffer]="bufferAttribute()">
71-
<ngts-decal *="let options" [mesh]="$any(mesh)" [options]="options">
72-
<ngt-mesh-physical-material
73-
[roughness]="0.2"
74-
[transparent]="true"
75-
[depthTest]="false"
76-
[map]="Math.random() > 0.5 ? decals()?.reactMap : decals()?.threeMap"
77-
[alphaTest]="0"
78-
[polygonOffset]="true"
79-
[polygonOffsetFactor]="-10"
80-
/>
81-
</ngts-decal>
82-
</decal-loop-over-instanced-buffer-attribute>
70+
@if (decals(); as decals) {
71+
<decal-loop-over-instanced-buffer-attribute [buffer]="bufferAttribute()">
72+
<ngts-decal *="let options" [mesh]="meshRef()" [options]="options">
73+
<ngt-mesh-physical-material
74+
[roughness]="0.2"
75+
[transparent]="true"
76+
[depthTest]="false"
77+
[map]="Math.random() > 0.5 ? decals.reactMap : decals.threeMap"
78+
[alphaTest]="0"
79+
[polygonOffset]="true"
80+
[polygonOffsetFactor]="-10"
81+
/>
82+
</ngts-decal>
83+
</decal-loop-over-instanced-buffer-attribute>
84+
}
8385
`,
8486
schemas: [CUSTOM_ELEMENTS_SCHEMA],
8587
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -108,10 +110,6 @@ class DefaultDecalStory {
108110
dummy.lookAt(p.add(normal));
109111
},
110112
}));
111-
112-
onClick(event: NgtThreeEvent<PointerEvent>) {
113-
console.log(event);
114-
}
115113
}
116114

117115
export default {

0 commit comments

Comments
 (0)