Skip to content

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

FIX: Only save post if post content changed when editing title (#36817)

Natalie Taye39c0d5d9699
diff --git a/frontend/discourse/app/models/composer.js b/frontend/discourse/app/models/composer.js
index a7bde2beca3..e35fa636219 100644
--- a/frontend/discourse/app/models/composer.js
+++ b/frontend/discourse/app/models/composer.js
@@ -1138,12 +1138,17 @@ export default class Composer extends RestModel {
const cooked = this.getCookedHtml();
post.setProperties({ cooked, staged: true });
+ // only save post if content changed as topic metadata is already handled above
+ const skipPostSave = !this.replyDirty && post.post_number === 1;
+ const savePromise = skipPostSave
+ ? Promise.resolve({ target: post, responseJson: { post } })
+ : post.save(props);
+
return promise
- .then(() => {
- return post.save(props).then((result) => {
- this.clearState();
- return result;
- });
+ .then(() => savePromise)
+ .then((result) => {
+ this.clearState();
+ return result;
})
.catch(rollback)
.finally(() => {
diff --git a/frontend/discourse/tests/acceptance/composer-test.js b/frontend/discourse/tests/acceptance/composer-test.js
index 5fd4ae2c99a..14e4e298ff8 100644
--- a/frontend/discourse/tests/acceptance/composer-test.js
+++ b/frontend/discourse/tests/acceptance/composer-test.js
@@ -598,6 +598,52 @@ acceptance(`Composer`, function (needs) {
.includesText("This is the new text for the post", "updates the post");
});
+ test("Editing post content calls post save", async function (assert) {
+ let postSaveCalled = false;
+
+ pretender.put("/posts/:post_id", () => {
+ postSaveCalled = true;
+ return response(200, { post: { id: 398, post_number: 1 } });
+ });
+
+ await visit("/t/internationalization-localization/280");
+
+ await click(".topic-post[data-post-number='1'] button.show-more-actions");
+ await click(".topic-post[data-post-number='1'] button.edit");
+
+ await fillIn(".d-editor-input", "This is new post content");
+ await click("#reply-control button.create");
+
+ assert.dom(".d-editor-input").doesNotExist("closes the composer");
+ assert.true(
+ postSaveCalled,
+ "post.save() should be called when content changes"
+ );
+ });
+
+ test("Editing only topic title does not call post save since content is unchanged", async function (assert) {
+ let postSaveCalled = false;
+
+ pretender.put("/posts/:post_id", () => {
+ postSaveCalled = true;
+ return response(200, { post: { id: 398, post_number: 1 } });
+ });
+
+ await visit("/t/internationalization-localization/280");
+
+ await click(".topic-post[data-post-number='1'] button.show-more-actions");
+ await click(".topic-post[data-post-number='1'] button.edit");
+
+ await fillIn("#reply-title", "This is a new title only");
+ await click("#reply-control button.create");
+
+ assert.dom(".d-editor-input").doesNotExist("closes the composer");
+ assert.false(
+ postSaveCalled,
+ "post.save() should not be called when only title changes"
+ );
+ });
+
test("Editing a post stages new content", async function (assert) {
await visit("/t/internationalization-localization/280");
await click(".topic-post button.show-more-actions");