@@ -57,7 +57,8 @@ class ApiDemoLayout extends LitElement {
57
57
@property ( { attribute : false } )
58
58
propKnobs ! : PropertyKnob [ ] ;
59
59
60
- private _whenDefined : Record < string , Promise < unknown > > = { } ;
60
+ @property ( { type : Boolean } )
61
+ private defined = false ;
61
62
62
63
private eventsController ! : EventsController ;
63
64
@@ -72,16 +73,7 @@ class ApiDemoLayout extends LitElement {
72
73
protected render ( ) : TemplateResult {
73
74
const { tag } = this ;
74
75
75
- // Invoke `requestUpdate` to render demo once the component is imported lazily
76
- // and becomes defined, but only it if matches the currently selected tag name.
77
- if ( ! customElements . get ( tag ) ) {
78
- this . _whenDefined [ tag ] = customElements . whenDefined ( tag ) ;
79
- this . _whenDefined [ tag ] . then ( ( ) => {
80
- if ( this . tag === tag ) {
81
- this . requestUpdate ( ) ;
82
- }
83
- } ) ;
84
-
76
+ if ( ! this . defined ) {
85
77
return html `
86
78
< div part ="warning ">
87
79
Element ${ tag } is not defined. Have you imported it?
@@ -190,6 +182,19 @@ class ApiDemoLayout extends LitElement {
190
182
willUpdate ( props : PropertyValues ) {
191
183
// Reset state if tag changed
192
184
if ( props . has ( 'tag' ) ) {
185
+ const { tag } = this ;
186
+ this . defined = ! ! customElements . get ( tag ) ;
187
+
188
+ if ( ! this . defined ) {
189
+ // Change `defined` to render demo once the component is imported lazily
190
+ // and becomes defined, but only if the corresponding tag is selected.
191
+ customElements . whenDefined ( tag ) . then ( ( ) => {
192
+ if ( this . tag === tag ) {
193
+ this . defined = true ;
194
+ }
195
+ } ) ;
196
+ }
197
+
193
198
this . knobs = { } ;
194
199
this . propKnobs = getKnobs ( this . tag , this . props , this . exclude ) ;
195
200
this . customKnobs = getCustomKnobs ( this . tag , this . vid ) ;
0 commit comments