Skip to content

A platform for community discussion. Free, open, simple.

FIX: Stop rich text images pulsing after uploads complete (#44220)

Alan Guo Xiang Tan0c86723eb20b
diff --git a/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs b/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs
index 7fdc1d67384..31c00173aff 100644
--- a/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs
+++ b/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs
@@ -173,6 +173,15 @@ export default class ImageNodeView extends Component {
return !!this.altMenuInstance?.content?.contains(document.activeElement);
}
+ update(node) {
+ if (this.#progressEvent && !node.attrs.placeholder) {
+ this.args.dom.classList.remove(...PLACEHOLDER_CLASSES);
+ delete this.args.dom.dataset.uploadId;
+ this.appEvents.off(this.#progressEvent, this, this.onUploadProgress);
+ this.#progressEvent = null;
+ }
+ }
+
stopEvent(event) {
if (["dragover", "dragend", "drop", "dragleave"].includes(event.type)) {
return false;
diff --git a/spec/system/composer/prosemirror_pasting_spec.rb b/spec/system/composer/prosemirror_pasting_spec.rb
index 197a9310606..e04797184ba 100644
--- a/spec/system/composer/prosemirror_pasting_spec.rb
+++ b/spec/system/composer/prosemirror_pasting_spec.rb
@@ -111,6 +111,7 @@ describe "Composer - ProseMirror - Pasting content" do
it "ignores text/html content if Files are present" do
open_composer
paste_and_click_image
+ expect(composer).to have_no_animated_images
expect(rich).to have_no_css("img[src^='data:']")
composer.focus # making sure the toggle click won't be captured as a double click
composer.toggle_rich_editor
diff --git a/spec/system/composer/prosemirror_uploads_spec.rb b/spec/system/composer/prosemirror_uploads_spec.rb
index 5fc49ac0b2f..d28c274d998 100644
--- a/spec/system/composer/prosemirror_uploads_spec.rb
+++ b/spec/system/composer/prosemirror_uploads_spec.rb
@@ -4,7 +4,7 @@ describe "Composer - ProseMirror - Uploads" do
include_context "with prosemirror editor"
describe "image uploads" do
- it "replaces the placeholder with the uploaded image without a transparent.png flash" do
+ it "shows the completed image without flashing or continuing to pulse" do
open_composer
file_path = file_from_fixtures("logo.png", "images").path
@@ -13,6 +13,10 @@ describe "Composer - ProseMirror - Uploads" do
expect(composer).to have_no_in_progress_uploads
expect(rich).to have_css(".composer-image-node img")
expect(rich).to have_no_css("img[src*='transparent.png']")
+ expect(composer).to have_no_animated_images
+
+ composer.type_content(" text after the image")
+ expect(composer).to have_no_animated_images
end
it "produces correct markdown after upload completes" do
@@ -39,6 +43,7 @@ describe "Composer - ProseMirror - Uploads" do
expect(composer).to have_no_in_progress_uploads
expect(rich).to have_css(".composer-image-node img", count: 2)
+ expect(composer).to have_no_animated_images
end
end
diff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rb
index c73fa6cdf02..455198d4ad5 100644
--- a/spec/system/page_objects/components/composer.rb
+++ b/spec/system/page_objects/components/composer.rb
@@ -26,6 +26,12 @@ module PageObjects
page.has_no_css?(RICH_EDITOR)
end
+ def has_no_animated_images?
+ page.has_no_css?("#{RICH_EDITOR} .composer-image-node img") do |image|
+ image.evaluate_script("getComputedStyle(this).animationName") != "none"
+ end
+ end
+
def opened?
page.has_css?("#{@composer_id}.open")
end