From c650cba17942ff9e940c2c88f26a4b756d9abc14 Mon Sep 17 00:00:00 2001 From: Rosa Gutierrez Date: Fri, 23 Jan 2026 13:29:33 +0100 Subject: [PATCH] Fix stuck state when permission granted but no subscription When you had already granted notification permission but hadn't completed the subscription flow (no service worker or no push subscription), the UI showed neither the subscribe button nor the enabled state, leaving you stuck with no way to subscribe, and wrong instructions to fix it. Instead, let's just show the button to allow you to subscribe. --- app/javascript/controllers/notifications_controller.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/javascript/controllers/notifications_controller.js b/app/javascript/controllers/notifications_controller.js index 02fce86d7..304bb279d 100644 --- a/app/javascript/controllers/notifications_controller.js +++ b/app/javascript/controllers/notifications_controller.js @@ -11,8 +11,7 @@ export default class extends Controller { switch(Notification.permission) { case "default": - this.subscribeButtonTarget.hidden = false - this.explainerTarget.hidden = true + this.#showButtonToSubscribe() break case "granted": const registration = await this.#getServiceWorkerRegistration() @@ -20,6 +19,8 @@ export default class extends Controller { if (registration && subscription) { this.element.classList.add(this.enabledClass) + } else { + this.#showButtonToSubscribe() } break } @@ -76,6 +77,11 @@ export default class extends Controller { } } + #showButtonToSubscribe() { + this.subscribeButtonTarget.hidden = false + this.explainerTarget.hidden = true + } + async #requestPermissionAndSubscribe(registration) { const permission = await Notification.requestPermission() if (permission === "granted") this.#subscribe(registration)