FIX: Issue with incorrect heights when cloaking plugin content in posts

FIX: Issue with incorrect heights when cloaking plugin content in posts

We noticed this with the house ads plugin. It inserted content after a post, which was not taken into account when calculating and memoizing the height of the element.

Co-authored-by: nlalonde Co-authored-by: pmusaraj

diff --git a/app/assets/javascripts/discourse/widgets/post-stream.js.es6 b/app/assets/javascripts/discourse/widgets/post-stream.js.es6
index 0515d8e..da059dc 100644
--- a/app/assets/javascripts/discourse/widgets/post-stream.js.es6
+++ b/app/assets/javascripts/discourse/widgets/post-stream.js.es6
@@ -34,7 +34,7 @@ export function cloak(post, component) {
     return;
   }
 
-  const $post = $(`#post_${post.post_number}`);
+  const $post = $(`#post_${post.post_number}`).parent();
   _cloaked[post.id] = true;
   _heights[post.id] = $post.outerHeight();

GitHub sha: fb1da53d

1 Like

I wonder how hard it would be to test that? No jumping around is an important feature.

Extremely hard to test in this case. I do think once we move to use the intersection API we can make this a lot cleaner. Right now it’s jQuery/hax central.

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: