masmerise / livewire-toaster

Beautiful toast notifications for Laravel / Livewire.
MIT License
342 stars 22 forks source link

Notification Doesn't Show Until Page Is Refresh #6

Closed ramonmalcolm10 closed 1 year ago

ramonmalcolm10 commented 1 year ago

When I trigger a success notification from Livewire component it doesn't show until page is refresh. Is it possible to show notification real time or I have to do some sort of redirect?

ramonmalcolm10 commented 1 year ago

Seems the issue is related to Laravel Octane, when I run the application using Octane I don't get the notification unless the page is refresh.

mabdullahsari commented 1 year ago

Sorry, but I don't use Octane. Feel free to submit a PR.

gazzoy commented 1 year ago

For those who are struggling with this problem, I found a solution. All you need to do is just put the following lines on config/octane.php, then it should work like a charm.

use Masmerise\Toaster\Collector;
...
 'warm' => [
      ...Octane::defaultServicesToWarm(),
      Collector::class, // To make Toaster works with Octane
 ],
...

As of I understood, Octane is very sensitive to singleton-ed property such as Collector in ToasterServiceProvider. By adding Collector in warm lists , Octane should be able to take care of Collector instance in Livewire request processing.

Hope this would help.

ramonmalcolm10 commented 1 year ago

@gazzoy if a check is done to see if the application is being served by Octane and use bind instead of Singleton, would that solve the issue?

mabdullahsari commented 1 year ago

I'm pretty sure this issue would be solved by scoped, but again I don't use Octane so feel free to submit a PR. 🙂

gazzoy commented 1 year ago

@gazzoy if a check is done to see if the application is being served by Octane and use bind instead of Singleton, would that solve the issue?

@ramonmalcolm10 Yes, I guess so. But I was just too lazy to make PR for this, so that have solved by only fixing config/octane.php without touching anything on this library. Anyways, as @mabdullahsari suggested, you can try to fix the core of Toaster itself if you want.

mabdullahsari commented 1 year ago

I've seen that someone has forked the library and changed the singleton directive to scope which further validates my assumptions that the fix to this issue is changing the service binding to scoped. I have no clue why he did not open a PR, but anyway.

Potentially fixed in 1.2.1. Update the package and don't forget to remove the service from Octane's warm array.

Thanks.

gazzoy commented 11 months ago

This is awesome! Thanks for your great work.