From 32819127ddadf51e15cc8f47807591c4f5e85b99 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 16 Mar 2022 19:32:27 +0200 Subject: [PATCH] Do not reuse Promise instance in loadIcon in core --- packages/core/src/api/icons.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/core/src/api/icons.ts b/packages/core/src/api/icons.ts index cba97f3..36c94ac 100644 --- a/packages/core/src/api/icons.ts +++ b/packages/core/src/api/icons.ts @@ -357,15 +357,10 @@ export const loadIcons: IconifyLoadIcons = ( /** * Cache for loadIcon promises */ -type LoadIconResult = Promise>; -const iconsQueue = Object.create(null) as Record; - -export const loadIcon = (icon: IconifyIconName | string): LoadIconResult => { - if (typeof icon === 'string' && iconsQueue[icon] !== void 0) { - return iconsQueue[icon]; - } - - const result: LoadIconResult = new Promise((fulfill, reject) => { +export const loadIcon = ( + icon: IconifyIconName | string +): Promise> => { + return new Promise((fulfill, reject) => { const iconObj = typeof icon === 'string' ? stringToIcon(icon) : icon; loadIcons([iconObj || icon], (loaded) => { if (loaded.length && iconObj) { @@ -380,9 +375,4 @@ export const loadIcon = (icon: IconifyIconName | string): LoadIconResult => { reject(icon); }); }); - - if (typeof icon === 'string') { - iconsQueue[icon] = result; - } - return result; };