viconic-react-icons 1.5.1 → 1.5.3

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.
package/dist/index.js CHANGED
@@ -2013,6 +2013,7 @@ if (typeof document !== "undefined") {
2013
2013
  }
2014
2014
  var _kitMissQueues = {};
2015
2015
  var _kitMissTimers = {};
2016
+ var _kitQueued = {};
2016
2017
  function _resolveRegistry(prefix) {
2017
2018
  if (_kitRegistry[prefix]) return _kitRegistry[prefix];
2018
2019
  const kits = window.CopyIconsKit || {};
@@ -2036,6 +2037,9 @@ function _flushPendingMisses(prefix) {
2036
2037
  }
2037
2038
  function _dispatchBatchFetch(prefix, iconBaseName, entry) {
2038
2039
  const { kitId, api } = entry;
2040
+ if (!_kitQueued[kitId]) _kitQueued[kitId] = /* @__PURE__ */ new Set();
2041
+ if (_kitQueued[kitId].has(iconBaseName)) return;
2042
+ _kitQueued[kitId].add(iconBaseName);
2039
2043
  if (!_kitMissQueues[kitId]) _kitMissQueues[kitId] = /* @__PURE__ */ new Set();
2040
2044
  _kitMissQueues[kitId].add(iconBaseName);
2041
2045
  if (_kitMissTimers[kitId]) return;
@@ -2058,13 +2062,15 @@ function _dispatchBatchFetch(prefix, iconBaseName, entry) {
2058
2062
  W.icons[`${prefix}/${n}`] = svg;
2059
2063
  W.icons[n] = W.icons[n] || svg;
2060
2064
  }
2065
+ delete _kitQueued[kitId];
2061
2066
  try {
2062
2067
  document.dispatchEvent(new CustomEvent("viconic:ready", { detail: { prefix, kitId } }));
2063
2068
  } catch (e) {
2064
2069
  }
2065
2070
  }).catch(() => {
2071
+ delete _kitQueued[kitId];
2066
2072
  });
2067
- }, 0);
2073
+ }, 150);
2068
2074
  }
2069
2075
  function _queueKitMiss(prefix, iconBaseName) {
2070
2076
  if (typeof window === "undefined") return;
@@ -2168,18 +2174,13 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
2168
2174
  }
2169
2175
  }
2170
2176
  document.addEventListener("viconic:ready", tryInjectFromEvent);
2171
- const fallbackTimer = setTimeout(() => {
2172
- if (isInjected()) return;
2173
- tryInjectFromEvent();
2174
- if (!isInjected() && isKitIcon && prefixMatch) {
2175
- const prefix = prefixMatch[1];
2176
- const iconBaseName = prefixMatch[2];
2177
- _queueKitMiss(prefix, iconBaseName);
2178
- }
2179
- }, 50);
2177
+ if (!isInjected() && isKitIcon && prefixMatch) {
2178
+ const prefix = prefixMatch[1];
2179
+ const iconBaseName = prefixMatch[2];
2180
+ _queueKitMiss(prefix, iconBaseName);
2181
+ }
2180
2182
  return () => {
2181
2183
  document.removeEventListener("viconic:ready", tryInjectFromEvent);
2182
- clearTimeout(fallbackTimer);
2183
2184
  };
2184
2185
  }, [name, className, size, color, style]);
2185
2186
  const combinedStyle = {
package/dist/index.mjs CHANGED
@@ -1978,6 +1978,7 @@ if (typeof document !== "undefined") {
1978
1978
  }
1979
1979
  var _kitMissQueues = {};
1980
1980
  var _kitMissTimers = {};
1981
+ var _kitQueued = {};
1981
1982
  function _resolveRegistry(prefix) {
1982
1983
  if (_kitRegistry[prefix]) return _kitRegistry[prefix];
1983
1984
  const kits = window.CopyIconsKit || {};
@@ -2001,6 +2002,9 @@ function _flushPendingMisses(prefix) {
2001
2002
  }
2002
2003
  function _dispatchBatchFetch(prefix, iconBaseName, entry) {
2003
2004
  const { kitId, api } = entry;
2005
+ if (!_kitQueued[kitId]) _kitQueued[kitId] = /* @__PURE__ */ new Set();
2006
+ if (_kitQueued[kitId].has(iconBaseName)) return;
2007
+ _kitQueued[kitId].add(iconBaseName);
2004
2008
  if (!_kitMissQueues[kitId]) _kitMissQueues[kitId] = /* @__PURE__ */ new Set();
2005
2009
  _kitMissQueues[kitId].add(iconBaseName);
2006
2010
  if (_kitMissTimers[kitId]) return;
@@ -2023,13 +2027,15 @@ function _dispatchBatchFetch(prefix, iconBaseName, entry) {
2023
2027
  W.icons[`${prefix}/${n}`] = svg;
2024
2028
  W.icons[n] = W.icons[n] || svg;
2025
2029
  }
2030
+ delete _kitQueued[kitId];
2026
2031
  try {
2027
2032
  document.dispatchEvent(new CustomEvent("viconic:ready", { detail: { prefix, kitId } }));
2028
2033
  } catch (e) {
2029
2034
  }
2030
2035
  }).catch(() => {
2036
+ delete _kitQueued[kitId];
2031
2037
  });
2032
- }, 0);
2038
+ }, 150);
2033
2039
  }
2034
2040
  function _queueKitMiss(prefix, iconBaseName) {
2035
2041
  if (typeof window === "undefined") return;
@@ -2133,18 +2139,13 @@ var ViconicIcon = ({ name, className, style, size, color, ...props }) => {
2133
2139
  }
2134
2140
  }
2135
2141
  document.addEventListener("viconic:ready", tryInjectFromEvent);
2136
- const fallbackTimer = setTimeout(() => {
2137
- if (isInjected()) return;
2138
- tryInjectFromEvent();
2139
- if (!isInjected() && isKitIcon && prefixMatch) {
2140
- const prefix = prefixMatch[1];
2141
- const iconBaseName = prefixMatch[2];
2142
- _queueKitMiss(prefix, iconBaseName);
2143
- }
2144
- }, 50);
2142
+ if (!isInjected() && isKitIcon && prefixMatch) {
2143
+ const prefix = prefixMatch[1];
2144
+ const iconBaseName = prefixMatch[2];
2145
+ _queueKitMiss(prefix, iconBaseName);
2146
+ }
2145
2147
  return () => {
2146
2148
  document.removeEventListener("viconic:ready", tryInjectFromEvent);
2147
- clearTimeout(fallbackTimer);
2148
2149
  };
2149
2150
  }, [name, className, size, color, style]);
2150
2151
  const combinedStyle = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viconic-react-icons",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Viconic Smart Icons loader for React — supports Kit and 200k+ system icons",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/index.jsx CHANGED
@@ -62,6 +62,7 @@ if (typeof document !== 'undefined') {
62
62
  // ============================================
63
63
  const _kitMissQueues = {}; // kitId -> Set of icon names
64
64
  const _kitMissTimers = {}; // kitId -> timer handle
65
+ const _kitQueued = {}; // kitId -> Set of icon names already queued (prevents Strict Mode double-queue)
65
66
 
66
67
  function _resolveRegistry(prefix) {
67
68
  if (_kitRegistry[prefix]) return _kitRegistry[prefix];
@@ -89,9 +90,14 @@ function _flushPendingMisses(prefix) {
89
90
 
90
91
  function _dispatchBatchFetch(prefix, iconBaseName, entry) {
91
92
  const { kitId, api } = entry;
93
+ // Skip if already queued — prevents React Strict Mode double-invoke from making 2 requests
94
+ if (!_kitQueued[kitId]) _kitQueued[kitId] = new Set();
95
+ if (_kitQueued[kitId].has(iconBaseName)) return;
96
+ _kitQueued[kitId].add(iconBaseName);
92
97
  if (!_kitMissQueues[kitId]) _kitMissQueues[kitId] = new Set();
93
98
  _kitMissQueues[kitId].add(iconBaseName);
94
- if (_kitMissTimers[kitId]) return;
99
+ if (_kitMissTimers[kitId]) return; // already scheduled, will pick up new additions
100
+ // 150ms debounce: collect all icons across the full React render cycle
95
101
  _kitMissTimers[kitId] = setTimeout(() => {
96
102
  delete _kitMissTimers[kitId];
97
103
  const names = [...(_kitMissQueues[kitId] || [])];
@@ -113,10 +119,12 @@ function _dispatchBatchFetch(prefix, iconBaseName, entry) {
113
119
  W.icons[`${prefix}/${n}`] = svg;
114
120
  W.icons[n] = W.icons[n] || svg;
115
121
  }
122
+ // Clear queued tracking so future kit updates can refetch
123
+ delete _kitQueued[kitId];
116
124
  try { document.dispatchEvent(new CustomEvent('viconic:ready', { detail: { prefix, kitId } })); } catch(e) {}
117
125
  })
118
- .catch(() => {});
119
- }, 0);
126
+ .catch(() => { delete _kitQueued[kitId]; });
127
+ }, 150);
120
128
  }
121
129
 
122
130
  function _queueKitMiss(prefix, iconBaseName) {
@@ -288,21 +296,17 @@ export const ViconicIcon = ({ name, className, style, size, color, ...props }) =
288
296
 
289
297
  document.addEventListener('viconic:ready', tryInjectFromEvent);
290
298
 
291
- // --- PATH 5: Short-deadline fallback (50ms) — queue a batch fetch for all missing kit icons ---
292
- const fallbackTimer = setTimeout(() => {
293
- if (isInjected()) return;
294
- tryInjectFromEvent();
295
- if (!isInjected() && isKitIcon && prefixMatch) {
296
- const prefix = prefixMatch[1];
297
- const iconBaseName = prefixMatch[2];
298
- // Use batch queue instead of kit.reload() to avoid N separate API calls
299
- _queueKitMiss(prefix, iconBaseName);
300
- }
301
- }, 50);
299
+ // --- PATH 5: Immediate queue for missing kit icons ---
300
+ // Call _queueKitMiss immediately (no per-component delay) so all icons from
301
+ // the same render cycle are collected into the same debounced batch request.
302
+ if (!isInjected() && isKitIcon && prefixMatch) {
303
+ const prefix = prefixMatch[1];
304
+ const iconBaseName = prefixMatch[2];
305
+ _queueKitMiss(prefix, iconBaseName);
306
+ }
302
307
 
303
308
  return () => {
304
309
  document.removeEventListener('viconic:ready', tryInjectFromEvent);
305
- clearTimeout(fallbackTimer);
306
310
  };
307
311
  }, [name, className, size, color, style]);
308
312