Skip to content

Commit 556bad4

Browse files
[HDS-4345] - Fix double loading of flight icons in engines (#2792)
1 parent df63408 commit 556bad4

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

packages/components/src/instance-initializers/load-sprite.ts

+12-18
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@
44
*/
55

66
import config from 'ember-get-config';
7-
import type ApplicationInstance from '@ember/application/instance';
87

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) {
1910
const { default: svgSprite } = await import(
2011
// @ts-expect-error: missing types
2112
'@hashicorp/flight-icons/svg-sprite/svg-sprite-module'
@@ -24,15 +15,18 @@ export async function initialize(
2415
// in test environments we can inject the sprite directly into the ember testing container
2516
// to avoid issues with tools like Percy that only consider content inside that element
2617
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+
}
3023
} else {
31-
window.document?.body?.insertAdjacentHTML('beforeend', svgSprite);
32-
}
24+
const container = window.document?.body;
3325

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+
}
3630
}
3731
}
3832

0 commit comments

Comments
 (0)