Bug 226765 - Dynamically inserted inline-level element causes the adjacent float to shift down
Summary: Dynamically inserted inline-level element causes the adjacent float to shift ...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: Safari 14
Hardware: Mac (Intel) macOS 10.15
: P2 Normal
Assignee: zalan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-06-08 04:48 PDT by Sarkis
Modified: 2022-12-16 07:59 PST (History)
6 users (show)

See Also:


Attachments
Demonstration (888 bytes, text/html)
2021-06-08 04:48 PDT, Sarkis
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sarkis 2021-06-08 04:48:41 PDT
Created attachment 430831 [details]
Demonstration

The problem seems to happen only when there's a block-level element present next to the float. Removing the block-level element from the document (either dynamically or from source) resolves the problem.

The case is not only confined to dynamically inserted inline elements, but also includes out-of-flow inline elements that appear in-flow later (e.g., by changing their 'position' from 'absolute' to 'static').

Everything works just fine in case the inline element is already in flow on page load. The problem also disappears once I manually set the 'display' property of the containing element to 'none' and then revert it to its initial value.

The bug also affects Safari on iOS, thus affecting other mobile browsers as well.

Find the demonstration attached.
Comment 1 Radar WebKit Bug Importer 2021-06-15 04:49:15 PDT
<rdar://problem/79335914>
Comment 2 Ahmad Saleem 2022-12-16 02:34:37 PST
I am able to reproduce this with Safari Technology Preview 160 as well where "span" and "float" are not on same line, while Chrome Canary 110 and Firefox Nightly 110 match each other. Thanks!
Comment 3 zalan 2022-12-16 06:32:27 PST
It looks like this breaks when the content is dynamically inserted. The same content works fine when no DOM mutation happens.

<style>
  #container {
  width: 500px;
  border: 1px solid black;
}

#container::after {
  content: 'after content';
  display: block;
}

#floating {
  float: right;
  background-color: blue;
}
</style>
<div id="container"><div id="floating">Float</div></div>
<script>
document.body.offsetHeight;
container.prepend(document.createTextNode("PASS if same line as float"));
</script>

produces the following render tree:

B---YGLS- --* RenderView at (0,0) size 1111x663
B-----LS- --    HTML RenderBlock at (0,0) size 1111x663
B-------- --      BODY RenderBody at (8,8) size 1095x647
B-------- --        DIV RenderBlock at (0,0) size 502x38
B---YG--- --          RenderBlock at (1,1) size 500x18
I-------- --            #text RenderText "PASS if same line as float"
B-F------ --          DIV RenderBlock at (468.11,19) size 32.89x18
I-------- --            #text RenderText "Float"
B----G--- --          <pseudo> RenderBlock at (1,19) size 500x18)
I---YG--- --            RenderText "after content"

while 
<div id="container">PASS if same line as float<div id="floating">Float</div></div>

B---YGLS- --* RenderView at (0,0) size 1111x663)
B-----LS- --    HTML RenderBlock at (0,0) size 1111x663
B-------- --      BODY RenderBody at (8,8) size 1095x647
B-------- --        DIV RenderBlock at (0,0) size 502x38
B---YG--- --          RenderBlock at (1,1) size 500x18
I-------- --            #text RenderText "PASS if same line as float"
B-F------ --            DIV RenderBlock at (467.11,0) size 32.89x18
I-------- --              #text RenderText "Float"
B----G--- --          <pseudo> RenderBlock at (1,19) size 500x18
I---YG--- --            RenderText "after content"

Note that in the first case, the "PASS if same line as float" is wrapped in an anon block container.