nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.
https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue
MIT License
864 stars 37 forks source link

Race condition: app delays with loading (the same) icon #151

Open roymap opened 2 months ago

roymap commented 2 months ago

There is a race-condition that we finally found that was causing our app to "wait" for about 10 seconds.

if (!state.value?.[iconKey.value]) {
    isFetching.value = true
    state.value[iconKey.value] = await loadIcon(resolvedIcon.value).catch(() => undefined)
    isFetching.value = false
  }

If your page has 1000s of the same icon, the loadIcon gets called 1000s of times before the if statement is true. The loadIcon method is slower than nuxt-icon calling this with each icon on the page.

You need to set either another variable that designates that you are already loading this icon, or set state.value[iconKey.value] with a temporary non-falsy value.