Skip to content

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

FIX: ensure child margins are accounted for when cloaking posts (#45047)

Kris751546fa1fe0
diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scss
index e9f1b876a7c..7b967812281 100644
--- a/app/assets/stylesheets/common/base/topic-post.scss
+++ b/app/assets/stylesheets/common/base/topic-post.scss
@@ -971,6 +971,12 @@ aside.quote {
opacity: 0.4;
}
+// Child margins collapsing through a bare post wrapper aren't included in the
+// height measured when cloaking, so the placeholder would come out short
+:where(.post-stream > [data-post-number]) {
+ display: flow-root;
+}
+
.post-stream--cloaked {
min-height: 1px; // ensures that cloaked items have a minimum height to force the intersection observers to work
overflow-anchor: none; // cloaked posts are empty placeholders with approximate height and must not be used as scroll anchors
diff --git a/spec/system/post_stream_spec.rb b/spec/system/post_stream_spec.rb
index 3e3b01ef3f4..37d45bd378d 100644
--- a/spec/system/post_stream_spec.rb
+++ b/spec/system/post_stream_spec.rb
@@ -176,4 +176,41 @@ describe "Post stream" do
expect(blockquote).to have_content(first_post.raw)
end
end
+
+ context "when cloaking a small action in a personal message" do
+ let!(:pm) { Fabricate(:private_message_topic, user: user) }
+ let!(:first_post) { Fabricate(:post, topic: pm, user: user) }
+ let!(:small_action) do
+ Fabricate(:small_action, topic: pm, user: user, action_code: "closed.enabled")
+ end
+ let!(:replies) do
+ Fabricate.times(10, :post, topic: pm, user: user, raw: "Hello world\n\n" * 20)
+ end
+
+ before { sign_in(user) }
+
+ def space_taken(selector)
+ page.evaluate_script(<<~JS)
+ (() => {
+ const el = document.querySelector(#{selector.to_json});
+ return el.nextElementSibling.getBoundingClientRect().top - el.getBoundingClientRect().top;
+ })()
+ JS
+ end
+
+ # A placeholder that takes up less space than the post it replaces shifts the
+ # page, which can push the post back across the cloaking boundary in a loop.
+ it "keeps the same space taken by the post when it is cloaked" do
+ visit "/t/#{pm.slug}/#{pm.id}/1"
+
+ selector = ".post-stream > [data-post-number='#{small_action.post_number}']"
+ expect(page).to have_css("#{selector} .small-action")
+ uncloaked_space = space_taken(selector)
+
+ send_keys(:end)
+
+ expect(page).to have_css("#{selector}.post-stream--cloaked")
+ expect(space_taken(selector)).to be_within(0.5).of(uncloaked_space)
+ end
+ end
end