@@ -287,23 +287,7 @@ class NgtRenderer implements Renderer2 {
287
287
}
288
288
}
289
289
290
- const shouldFindGrandparentInstance =
291
- // if child is three but haven't been attached to a parent yet
292
- ( cRS [ NgtRendererClassId . type ] === 'three' && ! untracked ( getLocalState ( newChild ) . parent ) ) ||
293
- // or both parent and child are DOM elements
294
- // or they are compound AND haven't had a THREE instance yet
295
- ( ( pRS [ NgtRendererClassId . type ] === 'dom' ||
296
- ( pRS [ NgtRendererClassId . type ] === 'compound' && ! pRS [ NgtRendererClassId . compounded ] ) ) &&
297
- ( cRS [ NgtRendererClassId . type ] === 'dom' ||
298
- ( cRS [ NgtRendererClassId . type ] === 'compound' && ! cRS [ NgtRendererClassId . compounded ] ) ) ) ||
299
- // or the parent is a non-compounded compound
300
- // and the child is a compounded compound
301
- ( ( pRS [ NgtRendererClassId . type ] === 'dom' ||
302
- ( pRS [ NgtRendererClassId . type ] === 'compound' && ! pRS [ NgtRendererClassId . compounded ] ) ) &&
303
- cRS [ NgtRendererClassId . type ] === 'compound' &&
304
- ! ! cRS [ NgtRendererClassId . compounded ] ) ;
305
-
306
- if ( shouldFindGrandparentInstance ) {
290
+ if ( this . shouldFindGrandparentInstance ( pRS , cRS , newChild ) ) {
307
291
// we'll try to get the grandparent instance here so that we can run appendChild with both instances
308
292
const closestGrandparentInstance = this . store . getClosestParentWithInstance ( parent ) ;
309
293
if ( closestGrandparentInstance ) this . appendChild ( closestGrandparentInstance , newChild ) ;
@@ -461,6 +445,28 @@ class NgtRenderer implements Renderer2 {
461
445
return ( ) => { } ;
462
446
}
463
447
448
+ private shouldFindGrandparentInstance ( pRS : NgtRendererState , cRS : NgtRendererState , child : NgtRendererNode ) {
449
+ const pType = pRS [ NgtRendererClassId . type ] ;
450
+ const cType = cRS [ NgtRendererClassId . type ] ;
451
+ const isParentCompounded = pRS [ NgtRendererClassId . compounded ] ;
452
+ const isChildCompounded = cRS [ NgtRendererClassId . compounded ] ;
453
+
454
+ // if child is three but haven't been attached to a parent yet
455
+ const isDanglingThreeChild = cType === 'three' && ! untracked ( getLocalState ( child ) . parent ) ;
456
+ // or both parent and child are DOM elements
457
+ // or they are compound AND haven't had a THREE instance yet
458
+ const isParentStillDOM = pType === 'dom' || ( pType === 'compound' && ! isParentCompounded ) ;
459
+ const isChildStillDOM = cType === 'dom' || ( cType === 'compound' && ! isChildCompounded ) ;
460
+ // and the child is a compounded compound
461
+ const isCompoundChildCompounded = cType === 'compound' && ! ! isChildCompounded ;
462
+
463
+ return (
464
+ isDanglingThreeChild ||
465
+ ( isParentStillDOM && isChildStillDOM ) ||
466
+ ( isParentStillDOM && isCompoundChildCompounded )
467
+ ) ;
468
+ }
469
+
464
470
createText = this . delegate . createText . bind ( this . delegate ) ;
465
471
destroy = this . delegate . destroy . bind ( this . delegate ) ;
466
472
destroyNode : ( ( node : any ) => void ) | null = null ;
0 commit comments