-
Notifications
You must be signed in to change notification settings - Fork 202
Closed
Description
Echo Version
@laravel/echo-vue 2.2.0
Laravel Version
12.29.0
PHP Version
8.4.2
NPM Version
10.9.2
Database Driver & Version
MySql 8.4.5 (Ubuntu x64)
Description
When using the useEchoNotification hook inside a component that is part of the app layout, the onUnmount function is not automatically triggered.
This causes the logic inside the callback passed to useEchoNotification to be duplicated, as shown in the attached screenshot.
Expected behavior
When the component is unmounted, the subscription should be properly cleaned up so that the callback is not executed multiple times.
Current behavior
The callback is registered multiple times and therefore executed multiple times for each notification.
Possible solution
I suspect it is necessary to add the following code inside useEchoNotification to properly handle component unmount:
onUnmounted(() => {
result.leave();
});Steps To Reproduce
- Create a component that is part of the app layout.
- Inside the component, use the
useEchoNotificationhook with a simple callback (e.g.console.log('Notification received')). - Navigate through the application so that the layout component is mounted/unmounted multiple times.
- Trigger an event that should call the notification callback.
- Observe that the callback is executed multiple times instead of once.
anotherfrontendguy
Metadata
Metadata
Assignees
Labels
No labels
