vue-sonner icon indicating copy to clipboard operation
vue-sonner copied to clipboard

How do I use `toast.promise` properly in Nuxt?

Open jonasfroeller opened this issue 10 months ago • 5 comments

I want to create a toast using a composable and the promise state should be reflected on other pages too, but it seems like the Promise is only active and resolvable on that page, where it is created.

The promise is pending till I move back to the page, where it was created.

jonasfroeller avatar Feb 13 '25 21:02 jonasfroeller

Are you defining the <Toaster> component within the layout?

tre-dev avatar Feb 24 '25 17:02 tre-dev

@tre-dev

No.

app.vue

<template>
  <div>
    <ConfigProvider :use-id="useSsrSaveId">
      <ShadcnToaster
        close-button
        position="top-center"
        offset="1.5rem"
      />
      <NuxtLoadingIndicator
        color="hsl(var(--primary) / 0.9)"
        error-color="hsl(var(--destructive))"
        :height="3"
        :duration="2000"
        :throttle="200"
      />
      <DynamicMeta :key="currentRouteName" />
      <div>
        <NuxtRouteAnnouncer />
        <NuxtLayout>
          <NuxtPage />
        </NuxtLayout>
      </div>
    </ConfigProvider>
  </div>
</template>

jonasfroeller avatar Feb 24 '25 22:02 jonasfroeller

$toast causes the same issue. The toast stays undismissable and loads infinite.

jonasfroeller avatar Feb 24 '25 23:02 jonasfroeller

Hm. Works fine for me. layouts/default.vue

<template>
  <div>
    <Toaster
      position="bottom-right"
      theme="dark"
    />
    <slot />
  </div>
</template>

tre-dev avatar Feb 25 '25 17:02 tre-dev

Okay. You put it in a layout. I didn't. I will try that today.
Edit: Didn't help.

jonasfroeller avatar Feb 25 '25 17:02 jonasfroeller