4
4
*/
5
5
6
6
import config from 'ember-get-config' ;
7
- import type ApplicationInstance from '@ember/application/instance' ;
8
7
9
- export async function initialize (
10
- appInstance : ApplicationInstance & {
11
- __flightIconsSpriteLoaded ?: boolean ;
12
- }
13
- ) {
14
- if (
15
- config ?. emberFlightIcons ?. lazyEmbed &&
16
- // we use this flag to avoid loading the sprite multiple times
17
- appInstance . __flightIconsSpriteLoaded !== true
18
- ) {
8
+ export async function initialize ( ) {
9
+ if ( config ?. emberFlightIcons ?. lazyEmbed ) {
19
10
const { default : svgSprite } = await import (
20
11
// @ts -expect-error: missing types
21
12
'@hashicorp/flight-icons/svg-sprite/svg-sprite-module'
@@ -24,15 +15,18 @@ export async function initialize(
24
15
// in test environments we can inject the sprite directly into the ember testing container
25
16
// to avoid issues with tools like Percy that only consider content inside that element
26
17
if ( config . environment === 'test' ) {
27
- window . document
28
- ?. getElementById ( 'ember-testing' )
29
- ?. insertAdjacentHTML ( 'afterbegin' , svgSprite ) ;
18
+ const container = window . document ?. getElementById ( 'ember-testing' ) ;
19
+
20
+ if ( container && ! container . querySelector ( '.flight-sprite-container' ) ) {
21
+ container . insertAdjacentHTML ( 'afterbegin' , svgSprite ) ;
22
+ }
30
23
} else {
31
- window . document ?. body ?. insertAdjacentHTML ( 'beforeend' , svgSprite ) ;
32
- }
24
+ const container = window . document ?. body ;
33
25
34
- // set the flag to avoid loading the sprite multiple times
35
- appInstance . __flightIconsSpriteLoaded = true ;
26
+ if ( container && ! container . querySelector ( '.flight-sprite-container' ) ) {
27
+ container . insertAdjacentHTML ( 'beforeend' , svgSprite ) ;
28
+ }
29
+ }
36
30
}
37
31
}
38
32
0 commit comments