@@ -28,6 +28,7 @@ export class UUIIconElement extends LitElement {
28
28
] ;
29
29
30
30
private _name : string | null = null ;
31
+ private _retrievedNameIcon : boolean = false ;
31
32
32
33
@state ( )
33
34
private _nameSvg : string | null = null ;
@@ -45,7 +46,9 @@ export class UUIIconElement extends LitElement {
45
46
}
46
47
set name ( newValue ) {
47
48
this . _name = newValue ;
48
- this . requestIcon ( ) ;
49
+ if ( this . shadowRoot ) {
50
+ this . requestIcon ( ) ;
51
+ }
49
52
}
50
53
private requestIcon ( ) {
51
54
if ( this . _name !== '' && this . _name !== null ) {
@@ -54,11 +57,13 @@ export class UUIIconElement extends LitElement {
54
57
} ) ;
55
58
this . dispatchEvent ( event ) ;
56
59
if ( event . icon !== null ) {
60
+ this . _retrievedNameIcon = true ;
57
61
event . icon . then ( ( iconSvg : string ) => {
58
62
this . _useFallback = false ;
59
63
this . _nameSvg = iconSvg ;
60
64
} ) ;
61
65
} else {
66
+ this . _retrievedNameIcon = false ;
62
67
this . _useFallback = true ;
63
68
}
64
69
}
@@ -87,15 +92,20 @@ export class UUIIconElement extends LitElement {
87
92
88
93
connectedCallback ( ) {
89
94
super . connectedCallback ( ) ;
90
- if ( this . _name !== '' && this . _name !== null ) {
91
- if ( this . _nameSvg === null ) {
92
- this . requestIcon ( ) ;
93
- }
95
+ if ( this . _retrievedNameIcon === false ) {
96
+ this . requestIcon ( ) ;
94
97
}
95
98
}
96
99
97
100
disconnectedCallback ( ) : void {
98
- this . _nameSvg = null ;
101
+ this . _retrievedNameIcon = false ;
102
+ }
103
+
104
+ firstUpdated ( ) {
105
+ // Registry might not have been created then this icon was connected, so therefor we will make another attempt to retrieve the icon.
106
+ if ( this . _retrievedNameIcon === false ) {
107
+ this . requestIcon ( ) ;
108
+ }
99
109
}
100
110
101
111
render ( ) {
0 commit comments