Base solution for your next web application
Open Closed

header-notifications.component not updating #11000


User avatar
0
chrisweinmuellner created
  • Production Version 11.1
  • Angular
  • .net Core
  • Theme Default, but applies to all themes

When receiving notifications (I only tried to reproduce with custom notifications, but my impression is that it applies to your default notifications too), the unreadNotificationCount on header-notifications.component isn't increased, the list of current notifications doesn't update without a page reload and subsequently no desktop push notification is created. After investigating and adding a try-catch-block in onNotificationReceived, this error trace pops up:

TypeError: date.toFormat is not a function
    at DateTimeService.formatDate (date-time.service.ts:163:21)
    at UserNotificationHelper.format (UserNotificationHelper.ts:104:41)
    at UserNotificationHelper.show (UserNotificationHelper.ts:138:28)
    at onNotificationReceived (header-notifications.component.ts:71:46)
    at header-notifications.component.ts:82:17
    at _ZoneDelegate.invoke (zone.js:372:1)
    at Object.onInvoke (core.mjs:25548:1)
    at _ZoneDelegate.invoke (zone.js:371:1)
    at Zone.run (zone.js:134:1)
    at NgZone.run (core.mjs:25402:1)

Tracing it back reveals that userNotification.notification.creationTime is supposed to be either Date or DateTime. It is a json datestring, but it is typeof "string". As a workaround, I implemented this:

function onNotificationReceived(userNotification) {
    if (typeof(userNotification.notification.creationTime) == "string") {
        userNotification.notification.creationTime = new Date(Date.parse(userNotification.notification.creationTime));
    }
    self._userNotificationHelper.show(userNotification);
    self.loadNotifications();

It fixes the immediate problem and desktop notifications work again, but I suppose there is a deeper issue here, so maybe you could have a look. I'm not aware of any changes that might have caused this on my codebase.

Also, while testing I stumbled upon an issue with the same message getting 10 and more calls to onNotificationReceived, but I can't reproduce easily, so maybe just be on the lookout for something similar.


1 Answer(s)