Skip to content

Troubleshooting

This page helps resolve the most common issues and explains the fallback mechanism in detail.

const notificationStore = getNotificationStore();
console.log('Connected:', notificationStore.isConnected);

Expected result:

  • true — Socket.IO is working, real-time notifications
  • false — Fallback mode, 30s polling

Server console:

Terminál
[Socket.IO] Client connected: abc123
[Socket.IO] User registered: 123
[Socket.IO] Notification sent to user: 123

Client console:

Terminál
[NotificationStore] Connected to Socket.IO
[NotificationStore] New notification received via WebSocket: {...}
[NotificationStore] About to show toast for notification: 1

If Socket.IO is unavailable, fallback activates automatically:

Terminál
# Client console
[NotificationStore] Connection error: ...
[NotificationStore] WebSocket disconnected, polling for notifications

Solution: No action needed, the system automatically switches to fallback mode.

await notificationStore.reload();
AspectSocket.IO (Primary)REST API (Fallback)
LatencyImmediate (< 100ms)30 seconds
Network trafficMinimalModerate (polling)
ReliabilityHighVery high
UsageAutomaticAutomatic fallback
ActivationOn connectionOn Socket.IO error
Terminál
# Stop the Socket.IO server
# The client will automatically switch to fallback mode
Terminál
[NotificationStore] Disconnected from Socket.IO
[NotificationStore] WebSocket disconnected, polling for notifications
await sendNotification({
userId: 123,
title: { hu: 'Teszt', en: 'Test' },
message: { hu: 'Fallback mód teszt', en: 'Fallback mode test' },
type: 'info'
});
// The notification will appear within 30 seconds
+layout.svelte
<script>
import { Toaster } from 'svelte-sonner';
</script>
<Toaster />

Solution: Add the Toaster component to the layout.

Critical type notifications don’t appear as toasts — they appear in a modal dialog.

// ❌ Won't show as toast
await sendNotification({
userId: 123,
title: 'Critical',
message: 'This appears in a modal dialog',
type: 'critical'
});
// ✅ Will show as toast
await sendNotification({
userId: 123,
title: 'Info',
message: 'This appears as a toast',
type: 'info'
});
Terminál
[NotificationStore] About to show toast for notification: 1
[NotificationStore] Toast imported successfully
[NotificationStore] Showing toast: { title: '...', message: '...', type: 'info' }

Symptom: isConnected is always false

Solution: The system automatically switches to fallback mode. Use the reload() method for manual refresh:

const notificationStore = getNotificationStore();
await notificationStore.reload();

Issue: Toast Notifications Not Appearing in Dev Mode

Section titled “Issue: Toast Notifications Not Appearing in Dev Mode”

Symptom: New notifications don’t appear automatically

Solution: The reload() method automatically shows toasts for new notifications:

// In notification-demo app
if (import.meta.env.DEV) {
setTimeout(() => {
notificationStore.reload();
}, 500);
}

Issue: Notifications Don’t Update Automatically

Section titled “Issue: Notifications Don’t Update Automatically”

Symptom: New notifications only appear after page refresh

Cause: Socket.IO is not running and polling hasn’t started yet

Solution: Wait 30 seconds, or use the reload() method:

await notificationStore.reload();

Only your own notifications can be deleted. Check that the userId matches the logged-in user.

// ✅ Good - deleting own notification
await notificationStore.deleteNotification(myNotificationId);
// ❌ Error - deleting another user's notification
await notificationStore.deleteNotification(otherUserNotificationId);
Terminál
# Successful deletion
[API] Notification deleted: 123
# Failed deletion
[API] Error deleting notification: Unauthorized
console.log('Notification permission:', Notification.permission);

Possible values:

  • granted — Allowed
  • denied — Blocked
  • default — Not yet requested
if (Notification.permission === 'default') {
await Notification.requestPermission();
}
if (!('Notification' in window)) {
console.error('Browser does not support notifications');
}

Check the CriticalNotificationDialog Component

Section titled “Check the CriticalNotificationDialog Component”
Desktop.svelte
<script>
import CriticalNotificationDialog from '$lib/components/core/CriticalNotificationDialog.svelte';
</script>
<CriticalNotificationDialog />

Solution: Add the CriticalNotificationDialog component to the Desktop component.

// ✅ Good - critical type
await sendNotification({
userId: 123,
title: 'Critical',
message: 'This appears in a modal dialog',
type: 'critical'
});
// ❌ Wrong - error type (appears as toast)
await sendNotification({
userId: 123,
title: 'Error',
message: 'This appears as a toast',
type: 'error'
});

If there are too many notifications, the list may be slow.

Solution: Use pagination or delete old notifications:

// Delete all notifications
await notificationStore.deleteAllNotifications();
// Or delete only old ones (server-side)
await notificationRepository.deleteOlderThan(30); // older than 30 days

If polling is too frequent, increase the interval:

notificationStore.svelte.ts
setInterval(() => {
if (browser && !this.state.isConnected) {
this.loadNotifications();
}
}, 60000); // 60 seconds instead of 30
notificationStore.svelte.ts
console.log('[NotificationStore] Connected:', this.state.isConnected);
console.log('[NotificationStore] Notifications:', this.state.notifications);
console.log('[NotificationStore] Unread count:', this.state.unreadCount);

Open the browser DevTools Network tab and filter for:

  • socket.io — WebSocket connection
  • /api/notifications — REST API calls

Use Svelte DevTools to track state:

Terminál
# Install
npm install -D @sveltejs/vite-plugin-svelte-inspector
lib/server/socket/index.ts
logger.info('[Socket.IO] Notification sent to user:', userId);
logger.info('[Socket.IO] Unread count:', unreadCount);
ErrorCauseSolution
Notifications not appearingSocket.IO not runningWait 30s (fallback) or reload()
Toast not appearingToaster component missingAdd to layout
Critical dialog not appearingCriticalNotificationDialog missingAdd to Desktop
Notifications not deletingPermission errorCan only delete own notifications
Browser notifications not workingPermission missingRequest permission from user