Skip to content

Commit 088aa8c

Browse files
committed
load sprites if they have not been loaded in another initializer
1 parent c23bdcb commit 088aa8c

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

packages/components/addon-main.cjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@
44
*/
55

66
const { addonV1Shim } = require('@embroider/addon-shim');
7-
module.exports = addonV1Shim(__dirname);
7+
const flightIconSprite = require('@hashicorp/flight-icons/svg-sprite/svg-sprite-module');
8+
9+
module.exports = {
10+
...addonV1Shim(__dirname),
11+
contentFor(type, config) {
12+
if (!config.emberFlightIcons?.lazyEmbed && type === 'body-footer') {
13+
return flightIconSprite;
14+
}
15+
},
16+
};

packages/components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@floating-ui/dom": "^1.6.3",
4141
"@hashicorp/design-system-tokens": "^2.1.0",
4242
"@hashicorp/ember-flight-icons": "^5.1.2",
43+
"@hashicorp/flight-icons": "^3.3.0",
4344
"@oddbird/popover-polyfill": "^0.4.3",
4445
"decorator-transforms": "^1.1.0",
4546
"ember-a11y-refocus": "^4.1.0",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) HashiCorp, Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*/
5+
6+
import config from 'ember-get-config';
7+
import type ApplicationInstance from '@ember/application/instance';
8+
9+
export async function initialize(
10+
appInstance: ApplicationInstance & {
11+
__flightIconsSpriteLoaded?: boolean;
12+
}
13+
) {
14+
if (
15+
config?.emberFlightIcons?.lazyEmbed &&
16+
appInstance.__flightIconsSpriteLoaded !== true
17+
) {
18+
const { default: svgSprite } = await import(
19+
'@hashicorp/flight-icons/svg-sprite/svg-sprite-module'
20+
);
21+
22+
// in test environments we can inject the sprite directly into the ember testing container
23+
// to avoid issues with tools like Percy that only consider content inside that element
24+
if (config.environment === 'test') {
25+
window.document
26+
?.getElementById('ember-testing')
27+
?.insertAdjacentHTML('afterbegin', svgSprite);
28+
} else {
29+
window.document?.body?.insertAdjacentHTML('beforeend', svgSprite);
30+
}
31+
32+
appInstance.__flightIconsSpriteLoaded = true;
33+
}
34+
}
35+
36+
export default {
37+
initialize,
38+
};

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,7 @@ __metadata:
41174117
"@glint/template": "npm:^1.4.0"
41184118
"@hashicorp/design-system-tokens": "npm:^2.1.0"
41194119
"@hashicorp/ember-flight-icons": "npm:^5.1.2"
4120+
"@hashicorp/flight-icons": "npm:^3.3.0"
41204121
"@oddbird/popover-polyfill": "npm:^0.4.3"
41214122
"@rollup/plugin-babel": "npm:^6.0.4"
41224123
"@tsconfig/ember": "npm:^3.0.8"
@@ -4244,7 +4245,7 @@ __metadata:
42444245
languageName: unknown
42454246
linkType: soft
42464247

4247-
"@hashicorp/flight-icons@npm:^3.4.0, @hashicorp/flight-icons@workspace:^, @hashicorp/flight-icons@workspace:packages/flight-icons":
4248+
"@hashicorp/flight-icons@npm:^3.3.0, @hashicorp/flight-icons@npm:^3.4.0, @hashicorp/flight-icons@workspace:^, @hashicorp/flight-icons@workspace:packages/flight-icons":
42484249
version: 0.0.0-use.local
42494250
resolution: "@hashicorp/flight-icons@workspace:packages/flight-icons"
42504251
dependencies:

0 commit comments

Comments
 (0)