From 7fd2fb6b85cbbf7d42734da14ee32442755895e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Saquetim?= <1108771+megothss@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:37:14 -0300 Subject: [PATCH] DEV: Display feedback in the Glimmer post menu on iOS / iPadOS devices (#30594) This commit introduces a workaround for a behavior observed in Safari for iOS / iPadOS where the feedback message wasn't being displayed after clicking on the copy button in the Glimmer post menu --- .../discourse/app/lib/post-action-feedback.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/post-action-feedback.js b/app/assets/javascripts/discourse/app/lib/post-action-feedback.js index 28b741d5d77..3af27c97506 100644 --- a/app/assets/javascripts/discourse/app/lib/post-action-feedback.js +++ b/app/assets/javascripts/discourse/app/lib/post-action-feedback.js @@ -1,3 +1,4 @@ +import { next } from "@ember/runloop"; import { SVG_NAMESPACE } from "discourse-common/lib/icon-library"; import { i18n } from "discourse-i18n"; @@ -43,7 +44,11 @@ export function showAlert(postId, actionClass, messageKey, opts = {}) { const actionBtn = opts.actionBtn || document.querySelector(`${postSelector} .${actionClass}`); - actionBtn?.classList.add("post-action-feedback-button"); + // using `next` here is a workaround for a behavior observed in Safari for iOS / iPadOS + // that somehow trigger Ember to restore the button's original classes + next(() => { + actionBtn?.classList.add("post-action-feedback-button"); + }); createAlert(i18n(messageKey), postId, actionBtn); createCheckmark(actionBtn, actionClass, postId); @@ -73,7 +78,12 @@ function createCheckmark(btn, actionClass, postId) { } function styleBtn(btn) { - btn.classList.add("--activated", "--transition"); + // using `next` here is a workaround for a behavior observed in Safari for iOS / iPadOS + // that somehow trigger Ember to restore the button's original classes preventing the message/checkmark from being + // displayed + next(() => { + btn.classList.add("--activated", "--transition"); + }); setTimeout( () => btn.classList.remove("--activated"), TIMEOUT - TRANSITION_BUFFER