@momentum-design/components 0.139.0 → 0.139.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { html } from 'lit';
1
+ import { html, nothing } from 'lit';
2
2
  import { ROLE } from '../../utils/roles';
3
3
  import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
4
4
  import styles from './formfieldgroup.styles';
@@ -69,7 +69,9 @@ class FormfieldGroup extends FormfieldWrapper {
69
69
  }
70
70
  render() {
71
71
  return html `
72
- <div part="group-header">${this.renderLabel()} ${this.renderHelperText()}</div>
72
+ ${this.label || this.helpText
73
+ ? html `<div part="group-header">${this.renderLabel()} ${this.renderHelperText()}</div>`
74
+ : nothing}
73
75
  <slot></slot>
74
76
  `;
75
77
  }
@@ -12,6 +12,8 @@ const fetchIcon = async (request) => fetch(request).then(response => {
12
12
  }
13
13
  return response;
14
14
  });
15
+ // Map of in-flight fetch promises keyed by URL to deduplicate concurrent requests
16
+ const pendingFetches = new Map();
15
17
  /**
16
18
  * Fetches a dynamic SVG icon based on the provided `url`, `name` and `fileExtension`.
17
19
  * The fetch is aborted if the signal is aborted.
@@ -37,7 +39,8 @@ const svgFetch = async ({ url, name, fileExtension, cacheStrategy, cacheName, re
37
39
  // abort the previous fetch request if it is still pending
38
40
  // and create a new signal
39
41
  const signal = renewSignal();
40
- const request = new Request(`${url}/${name}.${fileExtension}`, {
42
+ const iconUrl = `${url}/${name}.${fileExtension}`;
43
+ const request = new Request(iconUrl, {
41
44
  signal,
42
45
  });
43
46
  // if there is no cache defined (cacheName and cacheStrategy properly set),
@@ -52,11 +55,16 @@ const svgFetch = async ({ url, name, fileExtension, cacheStrategy, cacheName, re
52
55
  if (responseFromCache) {
53
56
  return responseFromCache;
54
57
  }
58
+ // **Check for in-flight fetch for same URL**
59
+ const pending = pendingFetches.get(iconUrl);
60
+ if (pending) {
61
+ return pending;
62
+ }
55
63
  // **Otherwise, fetch and cache if successful**
56
64
  // Both fetchIcon() and iconsCache.set() "consume" the request,
57
65
  // so we need to make a copy.
58
66
  // (see https://developer.mozilla.org/en-US/docs/Web/API/Request/clone)
59
- return fetchIcon(request.clone()).then(response => {
67
+ const fetchPromise = fetchIcon(new Request(iconUrl)).then(response => {
60
68
  var _a;
61
69
  // This avoids caching responses that we know are errors
62
70
  // (i.e. HTTP status code of 4xx or 5xx).
@@ -66,7 +74,11 @@ const svgFetch = async ({ url, name, fileExtension, cacheStrategy, cacheName, re
66
74
  return (_a = iconsCache.set) === null || _a === void 0 ? void 0 : _a.call(iconsCache, request, response.clone()).then(() => response.text());
67
75
  }
68
76
  return response.text();
77
+ }).finally(() => {
78
+ pendingFetches.delete(iconUrl);
69
79
  });
80
+ pendingFetches.set(iconUrl, fetchPromise);
81
+ return fetchPromise;
70
82
  })
71
83
  .catch(error => {
72
84
  // Note that a HTTP error response (e.g. 404) will NOT trigger
@@ -12,6 +12,8 @@ const fetchIllustration = async (request) => fetch(request).then(response => {
12
12
  }
13
13
  return response;
14
14
  });
15
+ // Map of in-flight fetch promises keyed by URL to deduplicate concurrent requests
16
+ const pendingFetches = new Map();
15
17
  /**
16
18
  * Fetches a dynamic SVG illustration based on the provided `url`, `name` and `fileExtension`.
17
19
  * The fetch is aborted if the signal is aborted.
@@ -37,7 +39,8 @@ const svgFetch = async ({ url, name, fileExtension, cacheStrategy, cacheName, re
37
39
  // abort the previous fetch request if it is still pending
38
40
  // and create a new signal
39
41
  const signal = renewSignal();
40
- const request = new Request(`${url}/${name}.${fileExtension}`, {
42
+ const illustrationUrl = `${url}/${name}.${fileExtension}`;
43
+ const request = new Request(illustrationUrl, {
41
44
  signal,
42
45
  });
43
46
  // if there is no cache defined (cacheName and cacheStrategy properly set),
@@ -52,11 +55,16 @@ const svgFetch = async ({ url, name, fileExtension, cacheStrategy, cacheName, re
52
55
  if (responseFromCache) {
53
56
  return responseFromCache;
54
57
  }
58
+ // **Check for in-flight fetch for same URL**
59
+ const pending = pendingFetches.get(illustrationUrl);
60
+ if (pending) {
61
+ return pending;
62
+ }
55
63
  // **Otherwise, fetch and cache if successful**
56
64
  // Both fetchIllustration() and illustrationsCache.set() "consume" the request,
57
65
  // so we need to make a copy.
58
66
  // (see https://developer.mozilla.org/en-US/docs/Web/API/Request/clone)
59
- return fetchIllustration(request.clone()).then(response => {
67
+ const fetchPromise = fetchIllustration(new Request(illustrationUrl)).then(response => {
60
68
  var _a;
61
69
  // This avoids caching responses that we know are errors
62
70
  // (i.e. HTTP status code of 4xx or 5xx).
@@ -66,7 +74,11 @@ const svgFetch = async ({ url, name, fileExtension, cacheStrategy, cacheName, re
66
74
  return (_a = illustrationsCache.set) === null || _a === void 0 ? void 0 : _a.call(illustrationsCache, request, response.clone()).then(() => response.text());
67
75
  }
68
76
  return response.text();
77
+ }).finally(() => {
78
+ pendingFetches.delete(illustrationUrl);
69
79
  });
80
+ pendingFetches.set(illustrationUrl, fetchPromise);
81
+ return fetchPromise;
70
82
  })
71
83
  .catch(error => {
72
84
  // Note that a HTTP error response (e.g. 404) will NOT trigger
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@momentum-design/components",
3
3
  "packageManager": "yarn@3.2.4",
4
- "version": "0.139.0",
4
+ "version": "0.139.2",
5
5
  "engines": {
6
6
  "node": ">=24.0.0",
7
7
  "npm": ">=8.0.0"