windx-foobar / nuxt3-notifications

Nuxt 3 notification library 🗨️
https://windx-foobar.github.io/nuxt3-notifications/
MIT License
21 stars 5 forks source link

Usage in composable #1

Closed mfrascati closed 5 months ago

mfrascati commented 1 year ago

Hi thanks, for the module! Quick question: the module works fine in components, using this.$notify, but I'm trying to use it in a composable, in this way:

const notification = useNotification();
notification.notify({ type: "error", text: "test" });

but it doesn't show any notification, no error. Am I doing something wrong?

windx-foobar commented 1 year ago

@mfrascati Hi. I'm glad it was helpful to you

It's a bug @kyvg/vue3-notification, i think... After work HMR notification is work fine)

You tried?

windx-foobar commented 1 year ago

@mfrascati I will try to deal with this problem. thank you very much for issue!

daviddomkar commented 8 months ago

Hi. Please reopen this, the notification is still not working.

windx-foobar commented 8 months ago

Hi. Please reopen this, the notification is still not working.

Hi. Can u reproduce that case on stackblitz ? Thank you.

windx-foobar commented 8 months ago

You can check source code in docs. It is used there Composition API and working correctly... link

BramEsposito commented 6 months ago

I'm unable to get this to work as well.

Here is a Stackblitz project: https://stackblitz.com/edit/nuxt-starter-tjg71j

I had to disable ssr as well, because that generated a lot of hydration mismatch errors.


UPDATE with solution:

put your <NuxtNotifications /> component in the root of your app.vue and right before the closing </template> tag

windx-foobar commented 5 months ago

I'm unable to get this to work as well.

Here is a Stackblitz project: https://stackblitz.com/edit/nuxt-starter-tjg71j

I had to disable ssr as well, because that generated a lot of hydration mismatch errors.

UPDATE with solution:

put your <NuxtNotifications /> component in the root of your app.vue and right before the closing </template> tag

Hi. Thank you for detailed reproduce. I see that this doesn't work and I'll try to figure it out.

windx-foobar commented 5 months ago

Need reproduction it with newest version v1.2.1

BramEsposito commented 5 months ago

I'm still running into this issue.

I solved it for myself by falling back by using this reference to notify:

const app = useNuxtApp();

const notify = app.vueApp.config.globalProperties.$notify;

This seems to be an issue in the higher technology, maybe in nuxt or vite itself because:

It is the only file being loaded from the .cache directory though

This workaround works for me at the moment, so I'm leaving this be for now. It would be great if anybody wants to look further into this, though.

BramEsposito commented 5 months ago

Extra option to fix this: switch ssr to true in you nuxt.config.ts

windx-foobar commented 5 months ago

@BramEsposito Hi! Can u try clean .nuxt and node_modules/.cache and run dev build again?

windx-foobar commented 5 months ago

Hi everybody! Put your hands up 😻 Can anyone check that this problem is resolved in the new version? v1.2.2 @BramEsposito @daviddomkar

Playground

Thank you very much!

windx-foobar commented 5 months ago

Close because inactive

BramEsposito commented 4 months ago

Sorry, I couldn't make time before today.

I have reproduced the resolution and can confirm this works now with these versions:

as you can see here: https://stackblitz.com/edit/nuxt-starter-tjg71j

thanks for your awesome job!

windx-foobar commented 4 months ago

Sorry, I couldn't make time before today.

I have reproduced the resolution and can confirm this works now with these versions:

  • nuxt: 3.12.2
  • nuxt3-notifications: 1.2.2

as you can see here: https://stackblitz.com/edit/nuxt-starter-tjg71j

thanks for your awesome job!

Hi! Thanks for reproduce! And big thanks for idea use this code

const app = useNuxtApp();

const notify = app.vueApp.config.globalProperties.$notify;