FIX: page:changed was sometimes reporting the wrong URL

FIX: page:changed was sometimes reporting the wrong URL

(This change could be considered a little risky so we should keep an eye on it.)

The core issue here is that sometimes as far as the router was concerned we had transitioned to a route even if a Topic model was still in the process of loading. In this case the callback could not retrieve the correct title yet because it had not loaded.

This fix returns a promise from setupController when visiting a topic, which will have the router block until the topic is loaded. This means that the transition never triggers until the topic title is present.

Note: adding a test for this is basically impossible - it was super hard to reproduce even in a browser.

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 c592b85..275d870 100644
--- a/app/assets/javascripts/discourse/app/routes/topic-from-params.js
+++ b/app/assets/javascripts/discourse/app/routes/topic-from-params.js
@@ -33,7 +33,7 @@ export default DiscourseRoute.extend({
 
     params.forceLoad = true;
 
-    postStream
+    return postStream
       .refresh(params)
       .then(() => {
         // TODO we are seeing errors where closest post is null and this is exploding

GitHub sha: fc63f0d3

1 Like