Skip to content

Commit 665c975

Browse files
committed
Correctly preventing spamming of the subscribe button
in current implementation, every time the user clicks subscribe, a new listener gets added on top of the existing ones, causing multiple handlers to execute and an infinite loop of event listener additions.
1 parent ee76b47 commit 665c975

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

styles/all/template/webpush.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function PhpbbWebpush() {
237237
async function subscribeButtonHandler(event) {
238238
event.preventDefault();
239239

240-
subscribeButton.addEventListener('click', subscribeButtonHandler);
240+
subscribeButton.removeEventListener('click', subscribeButtonHandler);
241241

242242
try {
243243
// Prevent the user from clicking the subscribe button multiple times.
@@ -288,6 +288,8 @@ function PhpbbWebpush() {
288288
}
289289
console.error('Push subscription error:', error);
290290
phpbb.alert(subscribeButton.getAttribute('data-l-err'), error.message || subscribeButton.getAttribute('data-disabled-msg'));
291+
} finally {
292+
subscribeButton.addEventListener('click', subscribeButtonHandler);
291293
}
292294
}
293295

0 commit comments

Comments
 (0)