Bug 1877812 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Currently when we want to prevent the creation of duplicate notifications we use [getNotificationWithValue](https://searchfox.org/mozilla-central/search?q=getNotificationWithValue) to do something like this:

```js
// Don't create a second notification if one already exists.
if (notificationbox.getNotificationWithValue("foo")) {
  return;
```

`notificationbox.appendNotification` became async via the work in Bug 1845150, which led to at least one instance where we started showing duplicates of the same notification. Because creation is happening asynchronously [getNotificationWIthValue](https://searchfox.org/mozilla-central/rev/6e2e933cd6b7931e1d4e8bd8af8daa9788b27760/toolkit/content/widgets/notificationbox.js#64) is no longer necessarily a reliable way of checking whether a notification has already been created, since it's possible to call `appendNotification` multiple times in quick succession before the initial notification gets added.

In order to make things more reliable and to provide an easier way of ensuring we avoid creating duplicate notifications we may want to start tracking pending notifications in `notificationbox.js`. :mstriemer suggested something like `hasNotificationWithValue()` to let consumers know that a notification is already being created, or possibly changing the return value of `getNotificationWithValue()` in cases where creation is pending.
Currently when we want to prevent the creation of duplicate notifications we use [getNotificationWithValue](https://searchfox.org/mozilla-central/search?q=getNotificationWithValue) to do something like this:

```js
// Don't create a second notification if one already exists.
if (notificationbox.getNotificationWithValue("foo")) {
  return;
}
```

`notificationbox.appendNotification` became async via the work in Bug 1845150, which led to at least one instance where we started showing duplicates of the same notification. Because creation is happening asynchronously [getNotificationWIthValue](https://searchfox.org/mozilla-central/rev/6e2e933cd6b7931e1d4e8bd8af8daa9788b27760/toolkit/content/widgets/notificationbox.js#64) is no longer necessarily a reliable way of checking whether a notification has already been created, since it's possible to call `appendNotification` multiple times in quick succession before the initial notification gets added.

In order to make things more reliable and to provide an easier way of ensuring we avoid creating duplicate notifications we may want to start tracking pending notifications in `notificationbox.js`. :mstriemer suggested something like `hasNotificationWithValue()` to let consumers know that a notification is already being created, or possibly changing the return value of `getNotificationWithValue()` in cases where creation is pending.

Back to Bug 1877812 Comment 0