A platform for community discussion. Free, open, simple.
FIX: Skip restoring an upload placeholder that was never shown (#44336)
Sérgio Saquetima338ed471a47
diff --git a/frontend/discourse/app/lib/textarea-text-manipulation.ts b/frontend/discourse/app/lib/textarea-text-manipulation.tsindex b68576af97b..db2bab24878 100644--- a/frontend/discourse/app/lib/textarea-text-manipulation.ts+++ b/frontend/discourse/app/lib/textarea-text-manipulation.ts@@ -1334,6 +1334,13 @@ class TextareaPlaceholderHandler implements PlaceholderHandler {progressComplete(file: UppyFile): void {const placeholderData = this.#placeholders[file.id]!;++ // A preprocessor can complete a file without reporting progress for it, in+ // which case no processing placeholder was ever shown.+ if (placeholderData.processingPlaceholder === undefined) {+ return;+ }+this.textManipulation.replaceText(placeholderData.processingPlaceholder,placeholderData.uploadPlaceholderdiff --git a/frontend/discourse/tests/unit/lib/text-area-manipulaton-test.js b/frontend/discourse/tests/unit/lib/text-area-manipulaton-test.jsindex c45bc3b60b6..d84efdbb903 100644--- a/frontend/discourse/tests/unit/lib/text-area-manipulaton-test.js+++ b/frontend/discourse/tests/unit/lib/text-area-manipulaton-test.js@@ -149,4 +149,52 @@ module("Unit | Utility | text-area-manipulation", function (hooks) {assert.true(prevented, "native paste is prevented for handled rich paste");assert.strictEqual(textarea.value, "plain fallback");});++ test("placeholder - restores the upload text after processing", function (assert) {+ this.owner.lookup("service:composer").model = { reply: "" };+ const textarea = document.createElement("textarea");+ document.body.appendChild(textarea);+ const manipulation = new TextareaTextManipulation(getOwner(this), {+ textarea,+ });+ const file = { id: "file-1", name: "notes.txt" };++ try {+ manipulation.placeholder.insert(file);+ const uploading = textarea.value;++ manipulation.placeholder.progress(file);+ assert.notStrictEqual(textarea.value, uploading, "shows processing");++ manipulation.placeholder.progressComplete(file);+ assert.strictEqual(textarea.value, uploading, "restores uploading");+ } finally {+ textarea.remove();+ }+ });++ // A preprocessor can complete a file it never reported progress for, such as+ // the checksum step skipping every file when SubtleCrypto is unavailable.+ test("placeholder - leaves the text alone when processing never started", function (assert) {+ this.owner.lookup("service:composer").model = { reply: "" };+ const textarea = document.createElement("textarea");+ document.body.appendChild(textarea);+ const manipulation = new TextareaTextManipulation(getOwner(this), {+ textarea,+ });+ const file = { id: "file-1", name: "notes.txt" };++ try {+ textarea.value = "this value is undefined ";+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);+ manipulation.placeholder.insert(file);+ const uploading = textarea.value;++ manipulation.placeholder.progressComplete(file);++ assert.strictEqual(textarea.value, uploading);+ } finally {+ textarea.remove();+ }+ });});