Closed Bug 1918733 Opened 1 year ago Closed 11 days ago

`range.getBoundingClientRect()` has 0 width/height for `content-visibility: hidden`

Categories

(Core :: Layout, defect, P3)

Firefox 130
defect

Tracking

()

RESOLVED FIXED
147 Branch
Tracking Status
firefox147 --- fixed

People

(Reporter: nolan, Assigned: sickl8, Mentored)

References

(Blocks 1 open bug)

Details

(Keywords: good-first-bug)

Attachments

(5 files)

Attached file index.html

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0

Steps to reproduce:

  1. Open the attached index.html file
  2. The reported width/height should be non-zero, but in Firefox they are both zero.

Minimal repro:

<div style="content-visibility: hidden; contain-intrinsic-size: 100px 100px;">
    <span id="span">Hello</span>
</div>
<script>
    const range = document.createRange()
    range.selectNode(span.firstChild)
    console.log(range.getBoundingClientRect().width) // 0
</script>

Actual results:

The width/height of the reported bounding rect are both 0.

Expected results:

Per the CSS containment spec 1, layout should be forced on content-visibility: hidden elements if their size is requested by script, e.g. using getBoundingClientRect(). This works correctly in Firefox when calling getBoundingClientRect() on an element, but not on a Range that selects a text node (as in this repro).

Browsers that fail the test:

  • Firefox Nightly 132.0a1 (2024-09-09) (64-bit)

Browsers that pass the test:

  • Chromium 128.0.6613.119
  • Safari Technology Preview 202 (Safari 18.0 WebKit 19620.1.4.8)
Attached image firefox-repro.png
Attached image chromium-repro.png
Attached image safari-repro.png

The Bugbug bot thinks this bug should belong to the 'Core::Layout' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Layout
Product: Firefox → Core

A trivial fix could be something like changing this by aStartContainer->GetPrimaryFrame(FlushType::Layout);... That should cover most cases, though I suspect dealing with cases where the range spans different boundaries would be fun.

We should probably at least do that tho.

Mentor: emilio
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

aStartContainer doesn't have a method called GetPrimaryFrame.

Assignee: nobody → sickl8
Status: NEW → ASSIGNED
Pushed by ealvarez@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/37db33174d7b https://hg.mozilla.org/integration/autoland/rev/74f5c94d0433 Implement recommended fix for zero width/height on `range.getBoundingClientRect()`. r=emilio
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/56346 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 11 days ago
Resolution: --- → FIXED
Target Milestone: --- → 147 Branch
Upstream PR was closed without merging
Upstream PR merged by moz-wptsync-bot
Upstream PR merged by moz-wptsync-bot
QA Whiteboard: [qa-triage-done-c148/b147]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: