Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading icon remains visible after promise resolution when using the loading-icon slot #111

Open
pcoterecollective opened this issue Mar 13, 2025 · 4 comments

Comments

@pcoterecollective
Copy link

Type

  • Bug

Description

Loading icon remains visible after promise resolution when using the loading-icon slot

Expected result

Loading icon should disappear on promise resolution when using the loading-icon slot

Context

  • "vue-sonner": "^1.3.0"
  • "vite": "^6.0.7"
  • "vue": "^3.5.13"
  • "tailwindcss": "^3.4.17"
  • "lucide-vue-next": "^0.475.0"

Steps to reproduce

Create this simple Vue 3 app and click on the button

<script setup lang="ts">
// App.vue
import { Toaster, toast } from 'vue-sonner'
import { Loader } from 'lucide-vue-next'

const onClick = () => {
  toast.promise(() => new Promise((r) => setTimeout(r, 2000)), {
    loading: 'Loading...',
    success: () => 'Success',
    error: () => 'Error'
  })
}
</script>

<template>
  <div class="flex items-center justify-center h-screen w-screen">
    <Toaster class="toaster group" v-bind="props">
      <template #loading-icon>
        <Loader />
      </template>
    </Toaster>

    <button @click="onClick">Click me!</button>
  </div>
</template>

Image

@dany68
Copy link

dany68 commented Mar 19, 2025

Hi,
I confirm experiencing the same issue.

@pcoterecollective
Copy link
Author

Fix:

Replace the following lines

<div data-icon="" :class="cn(classes?.icon, toast?.classes?.icon)">
<template
v-if="(toast.promise || toastType === 'loading') && !toast.icon"
>
<slot name="loading-icon" />
</template>
<component :is="toast.icon" v-if="toast.icon" />
<template v-else>
<slot v-if="toastType === 'success'" name="success-icon" />
<slot v-else-if="toastType === 'error'" name="error-icon" />
<slot v-else-if="toastType === 'warning'" name="warning-icon" />
<slot v-else-if="toastType === 'info'" name="info-icon" />
</template>

with

          <component :is="toast.icon" v-if="toast.icon" />
          <template v-else>
            <slot v-if="toastType === 'loading'" name="loading-icon" />
            <slot v-else-if="toastType === 'success'" name="success-icon" />
            <slot v-else-if="toastType === 'error'" name="error-icon" />
            <slot v-else-if="toastType === 'warning'" name="warning-icon" />
            <slot v-else-if="toastType === 'info'" name="info-icon" />
          </template>

@xiaoluoboding
Copy link
Owner

@pcoterecollective Hi there, thanks for the fix! Please create a pull request so we can merge it.

@pcoterecollective
Copy link
Author

@xiaoluoboding
ERROR: Permission to xiaoluoboding/vue-sonner.git denied to ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants