@@ -37,7 +37,7 @@ import {
37
37
} from '@glimmer/debug' ;
38
38
import { registerDestructor } from '@glimmer/destroyable' ;
39
39
import { managerHasCapability } from '@glimmer/manager' ;
40
- import { createUnboundRef , isConstRef , REFERENCE , valueForRef } from '@glimmer/reference' ;
40
+ import { isConstRef , valueForRef } from '@glimmer/reference' ;
41
41
import {
42
42
assert ,
43
43
assign ,
@@ -56,6 +56,7 @@ import type { UpdatingVM } from '../../vm';
56
56
import type { InternalVM } from '../../vm/append' ;
57
57
import type { BlockArgumentsImpl } from '../../vm/arguments' ;
58
58
59
+ import { ConcreteBounds } from '../../bounds' ;
59
60
import { hasCustomDebugRenderTreeLifecycle } from '../../component/interfaces' ;
60
61
import { resolveComponent } from '../../component/resolve' ;
61
62
import { isCurriedType , isCurriedValue , resolveCurriedValue } from '../../curried-value' ;
@@ -491,44 +492,43 @@ export class ComponentElementOperations implements ElementOperations {
491
492
492
493
addModifier ( vm : InternalVM , modifier : ModifierInstance , capturedArgs : CapturedArguments ) : void {
493
494
this . modifiers . push ( modifier ) ;
494
- const env = vm . env ;
495
- if ( env . debugRenderTree ) {
496
- const element = vm . elements ( ) . constructing ! ;
497
- const name =
498
- modifier . definition . resolvedName ||
499
- ( modifier . state as any ) . debugName ||
500
- ( modifier . definition . state as any ) . name ||
501
- 'unknown-modifier' ;
502
- const instance = ( modifier . state as any ) . delegate || modifier . manager ;
503
- const args : any = {
504
- positional : [ ] ,
505
- named : { } ,
506
- } ;
507
- for ( const value of capturedArgs . positional ) {
508
- if ( value && value [ REFERENCE ] ) {
509
- args . positional . push ( value ) ;
510
- } else {
511
- args . positional . push ( createUnboundRef ( value , false ) ) ;
512
- }
513
- }
514
- for ( const [ key , value ] of Object . entries ( capturedArgs . named ) ) {
515
- args . named [ key ] = createUnboundRef ( value , false ) ;
495
+
496
+ if ( vm . env . debugRenderTree !== undefined ) {
497
+ const { manager, definition, state } = modifier ;
498
+
499
+ // TODO: we need a stable object for the debugRenderTree as the key, add support for
500
+ // the case where the state is a primitive, or if in practice we always have/require
501
+ // an object, then change the internal types to reflect that
502
+ if ( state === null || ( typeof state !== 'object' && typeof state !== 'function' ) ) {
503
+ return ;
516
504
}
517
- env . debugRenderTree . create ( modifier . state as any , {
505
+
506
+ let { element, constructing } = vm . elements ( ) ;
507
+ let name = manager . getDebugName ( definition ) ;
508
+ let instance = manager . getDebugInstance ( state ) ;
509
+
510
+ assert ( constructing , `Expected a constructing element in addModifier` ) ;
511
+
512
+ let bounds = new ConcreteBounds ( element , constructing , constructing ) ;
513
+
514
+ vm . env . debugRenderTree . create ( state , {
518
515
type : 'modifier' ,
519
516
name,
520
- args,
517
+ args : capturedArgs ,
521
518
instance,
522
519
} ) ;
523
- env . debugRenderTree ?. didRender ( modifier . state as any , {
524
- parentElement : ( ) => ( element as any ) . parentElement ,
525
- firstNode : ( ) => element ,
526
- lastNode : ( ) => element ,
520
+
521
+ vm . env . debugRenderTree . didRender ( state , bounds ) ;
522
+
523
+ // For tearing down the debugRenderTree
524
+ vm . associateDestroyable ( state ) ;
525
+
526
+ vm . updateWith ( new DebugRenderTreeUpdateOpcode ( state ) ) ;
527
+ vm . updateWith ( new DebugRenderTreeDidRenderOpcode ( state , bounds ) ) ;
528
+
529
+ registerDestructor ( state , ( ) => {
530
+ vm . env . debugRenderTree ?. willDestroy ( state ) ;
527
531
} ) ;
528
- registerDestructor (
529
- modifier . state as any ,
530
- ( ) => vm . env . debugRenderTree ?. willDestroy ( modifier . state as any )
531
- ) ;
532
532
}
533
533
}
534
534
@@ -684,8 +684,6 @@ APPEND_OPCODES.add(Op.GetComponentSelf, (vm, { op1: _state, op2: _names }) => {
684
684
instance : valueForRef ( selfRef ) ,
685
685
} ) ;
686
686
687
- vm . associateDestroyable ( instance ) ;
688
-
689
687
registerDestructor ( instance , ( ) => {
690
688
vm . env . debugRenderTree ?. willDestroy ( instance ) ;
691
689
} ) ;
0 commit comments