diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js
index 1776e9f5d1e..5b2c1e5a1b9 100644
--- a/app/assets/javascripts/discourse/app/models/topic.js
+++ b/app/assets/javascripts/discourse/app/models/topic.js
@@ -24,7 +24,7 @@ import DiscourseURL, { userPath } from "discourse/lib/url";
import deprecated from "discourse-common/lib/deprecated";
import { applyModelTransformations } from "discourse/lib/model-transformers";
-export function loadTopicView(topic, args) {
+export async function loadTopicView(topic, args) {
const data = deepMerge({}, args);
const url = `${getURL("/t/")}${topic.id}`;
const jsonUrl = (data.nearPost ? `${url}/${data.nearPost}` : url) + ".json";
@@ -33,12 +33,12 @@ export function loadTopicView(topic, args) {
delete data.__type;
delete data.store;
- return PreloadStore.getAndRemove(`topic_${topic.id}`, () =>
+ const json = await PreloadStore.getAndRemove(`topic_${topic.id}`, () =>
ajax(jsonUrl, { data })
- ).then((json) => {
- topic.updateFromJson(json);
- return json;
- });
+ );
+
+ topic.updateFromJson(json);
+ return json;
}
export const ID_CONSTRAINT = /^\d+$/;
diff --git a/app/assets/javascripts/discourse/app/routes/topic-from-params.js b/app/assets/javascripts/discourse/app/routes/topic-from-params.js
index 5875089d6d7..0dc639f03bd 100644
--- a/app/assets/javascripts/discourse/app/routes/topic-from-params.js
+++ b/app/assets/javascripts/discourse/app/routes/topic-from-params.js
@@ -80,6 +80,7 @@ export default DiscourseRoute.extend({
enteredAt: Date.now().toString(),
userLastReadPostNumber: topic.last_read_post_number,
highestPostNumber: topic.highest_post_number,
+ controllerReady: true,
});
this.appEvents.trigger("page:topic-loaded", topic);
diff --git a/app/assets/javascripts/discourse/app/routes/topic.js b/app/assets/javascripts/discourse/app/routes/topic.js
index 6764143a011..615b353e4e2 100644
--- a/app/assets/javascripts/discourse/app/routes/topic.js
+++ b/app/assets/javascripts/discourse/app/routes/topic.js
@@ -23,6 +23,7 @@ const TopicRoute = DiscourseRoute.extend({
isTransitioning: false,
scheduledReplace: null,
lastScrollPos: null,
+ controllerReady: true,
});
},
diff --git a/app/assets/javascripts/discourse/app/templates/topic.hbs b/app/assets/javascripts/discourse/app/templates/topic.hbs
index 85186edfe29..05a64c9d1e0 100644
--- a/app/assets/javascripts/discourse/app/templates/topic.hbs
+++ b/app/assets/javascripts/discourse/app/templates/topic.hbs
@@ -13,7 +13,7 @@
- {{#if this.model.postStream.loaded}}
+ {{#if (and this.controllerReady this.model.postStream.loaded)}}
{{#if this.model.postStream.firstPostPresent}}
{{#if this.editingTopic}}