File tree 7 files changed +79
-4
lines changed
src/instance-initializers
src/instance-initializers
7 files changed +79
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @hashicorp/design-system-components " : minor
3
+ ---
4
+
5
+ Loads the ` hds-icon ` sprite in the ` components ` package, and ensures it is only loaded once.
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
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 (
13
+ ! config . emberFlightIcons ?. lazyEmbed &&
14
+ ! config . __flightIconsSpriteLoaded &&
15
+ type === 'body-footer'
16
+ ) {
17
+ config . __flightIconsSpriteLoaded = true ;
18
+
19
+ return flightIconSprite ;
20
+ }
21
+ } ,
22
+ } ;
Original file line number Diff line number Diff line change 40
40
"@floating-ui/dom" : " ^1.6.3" ,
41
41
"@hashicorp/design-system-tokens" : " ^2.1.0" ,
42
42
"@hashicorp/ember-flight-icons" : " ^5.1.2" ,
43
+ "@hashicorp/flight-icons" : " ^3.4.0" ,
43
44
"decorator-transforms" : " ^1.1.0" ,
44
45
"ember-a11y-refocus" : " ^4.1.0" ,
45
46
"ember-cli-sass" : " ^11.0.1" ,
Original file line number Diff line number Diff line change
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
+ // we use this flag to avoid loading the sprite multiple times
17
+ appInstance . __flightIconsSpriteLoaded !== true
18
+ ) {
19
+ const { default : svgSprite } = await import (
20
+ '@hashicorp/flight-icons/svg-sprite/svg-sprite-module'
21
+ ) ;
22
+
23
+ // in test environments we can inject the sprite directly into the ember testing container
24
+ // to avoid issues with tools like Percy that only consider content inside that element
25
+ if ( config . environment === 'test' ) {
26
+ window . document
27
+ ?. getElementById ( 'ember-testing' )
28
+ ?. insertAdjacentHTML ( 'afterbegin' , svgSprite ) ;
29
+ } else {
30
+ window . document ?. body ?. insertAdjacentHTML ( 'beforeend' , svgSprite ) ;
31
+ }
32
+
33
+ // set the flag to avoid loading the sprite multiple times
34
+ appInstance . __flightIconsSpriteLoaded = true ;
35
+ }
36
+ }
37
+
38
+ export default {
39
+ initialize,
40
+ } ;
Original file line number Diff line number Diff line change @@ -8,7 +8,13 @@ const flightIconSprite = require('@hashicorp/flight-icons/svg-sprite/svg-sprite-
8
8
module . exports = {
9
9
...addonV1Shim ( __dirname ) ,
10
10
contentFor ( type , config ) {
11
- if ( ! config . emberFlightIcons ?. lazyEmbed && type === 'body-footer' ) {
11
+ if (
12
+ ! config . emberFlightIcons ?. lazyEmbed &&
13
+ ! config . __flightIconsSpriteLoaded &&
14
+ type === 'body-footer'
15
+ ) {
16
+ config . __flightIconsSpriteLoaded = true ;
17
+
12
18
return flightIconSprite ;
13
19
}
14
20
} ,
Original file line number Diff line number Diff line change 5
5
6
6
import config from 'ember-get-config' ;
7
7
8
- export async function initialize ( ) {
9
- if ( config ?. emberFlightIcons ?. lazyEmbed ) {
8
+ export async function initialize ( appInstance ) {
9
+ if (
10
+ config ?. emberFlightIcons ?. lazyEmbed &&
11
+ // we use this flag to avoid loading the sprite multiple times
12
+ appInstance . __flightIconsSpriteLoaded !== true
13
+ ) {
10
14
const { default : svgSprite } = await import (
11
15
'@hashicorp/flight-icons/svg-sprite/svg-sprite-module'
12
16
) ;
@@ -20,6 +24,9 @@ export async function initialize() {
20
24
} else {
21
25
window . document ?. body ?. insertAdjacentHTML ( 'beforeend' , svgSprite ) ;
22
26
}
27
+
28
+ // set the flag to avoid loading the sprite multiple times
29
+ appInstance . __flightIconsSpriteLoaded = true ;
23
30
}
24
31
}
25
32
Original file line number Diff line number Diff line change @@ -4110,6 +4110,7 @@ __metadata:
4110
4110
"@glint/template": "npm:^1.4.0"
4111
4111
"@hashicorp/design-system-tokens": "npm:^2.1.0"
4112
4112
"@hashicorp/ember-flight-icons": "npm:^5.1.2"
4113
+ "@hashicorp/flight-icons": "npm:^3.4.0"
4113
4114
"@rollup/plugin-babel": "npm:^6.0.4"
4114
4115
"@tsconfig/ember": "npm:^3.0.8"
4115
4116
"@types/ember-qunit": "npm:^6.1.1"
You can’t perform that action at this time.
0 commit comments