@@ -5,6 +5,7 @@ import { TemplateRefWrapper } from './template-ref-wrapper';
55import { render , type RootPart , type TemplateResult } from 'lit-html' ;
66
77type TemplateFunction = ( arg : any ) => TemplateResult ;
8+ const SCHEDULE_DELAY = 10 ;
89
910@Component ( {
1011 selector : 'igx-template-wrapper' ,
@@ -18,6 +19,7 @@ export class TemplateWrapperComponent {
1819 public templateRendered = new Subject < HTMLElement > ( ) ;
1920
2021 private childParts : WeakMap < HTMLElement , RootPart > = new WeakMap ( ) ;
22+ private timeoutId : NodeJS . Timeout | string | number | undefined ;
2123
2224 /**
2325 * All template refs
@@ -30,6 +32,15 @@ export class TemplateWrapperComponent {
3032 constructor ( private cdr : ChangeDetectorRef ) { }
3133
3234 protected litRender ( container : HTMLElement , templateFunc : ( arg : any ) => TemplateResult , arg : any ) {
35+ if ( ! container . isConnected ) {
36+ // Wait a bit if it gets attached back, otherwise do nothing
37+ this . timeoutId = setTimeout ( ( ) => {
38+ if ( container . isConnected ) {
39+ this . litRender ( container , templateFunc , arg ) ;
40+ }
41+ } , SCHEDULE_DELAY ) ;
42+ return ;
43+ }
3344 const part = render ( templateFunc ( arg ) , container ) ;
3445
3546 let existingPart = this . childParts . get ( container ) ;
@@ -71,5 +82,6 @@ export class TemplateWrapperComponent {
7182 this . childParts . get ( container ) . setConnected ( false ) ;
7283 this . childParts . delete ( container ) ;
7384 }
85+ clearTimeout ( this . timeoutId ) ;
7486 }
7587}
0 commit comments