A platform for community discussion. Free, open, simple.
DEV: Fix a rare bug where topic scrolls to OP unexpectedly (#34713)
Penar Musaraja218dfbc042e
diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.jsindex 3945bb99b95..93715130f32 100644--- a/app/assets/javascripts/discourse/app/controllers/topic.js+++ b/app/assets/javascripts/discourse/app/controllers/topic.js@@ -1831,13 +1831,16 @@ export default class TopicController extends Controller {}const postStream = this.get("model.postStream");+ const currentPostNumber = topic.get("currentPost");+ const opts =+ currentPostNumber > 1 ? { post_number: currentPostNumber } : {};if (data.reload_topic) {- topic.reload().then(() => {- this.send("postChangedRoute", topic.get("post_number") || 1);+ topic.reload(opts).then(() => {this.appEvents.trigger("header:update-topic", topic);if (data.refresh_stream) {- postStream.refresh();+ this.send("postChangedRoute", currentPostNumber || 1);+ postStream.refresh({ nearPost: currentPostNumber });}});diff --git a/app/assets/javascripts/discourse/app/models/post-stream.js b/app/assets/javascripts/discourse/app/models/post-stream.jsindex 0d6f7bad98b..c8f49a724b7 100644--- a/app/assets/javascripts/discourse/app/models/post-stream.js+++ b/app/assets/javascripts/discourse/app/models/post-stream.js@@ -327,7 +327,9 @@ export default class PostStream extends RestModel {**/refresh(opts) {opts = opts || {};- opts.nearPost = parseInt(opts.nearPost, 10);+ if (opts.nearPost) {+ opts.nearPost = parseInt(opts.nearPost, 10);+ }if (opts.cancelFilter) {this.cancelFilter();diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.jsindex d396188becd..d5b05c9e946 100644--- a/app/assets/javascripts/discourse/app/models/topic.js+++ b/app/assets/javascripts/discourse/app/models/topic.js@@ -823,10 +823,14 @@ export default class Topic extends RestModel {return this;}- reload() {- return ajax(`/t/${this.id}`, { type: "GET" }).then((topic_json) =>- this.updateFromJson(topic_json)- );+ reload(opts = {}) {+ const url = opts.post_number+ ? `/t/${this.id}?post_number=${opts.post_number}`+ : `/t/${this.id}`;++ return ajax(url, { type: "GET" }).then((topic_json) => {+ this.updateFromJson(topic_json);+ });}clearPin() {