Skip to content

Commit

Permalink
Don't make frame initial viewport size depend on whether it's been la…
Browse files Browse the repository at this point in the history
…id out.

This is rather tricky / unfortunate, but this is the low-risk fix for
now. The issue is as follows:

When we construct a subdocument frame, we try to show its viewer by
using a script runner which will call ShowViewer().

If ShowViewer() gets called before the subdoc frame gets laid out
(has the NS_FRAME_FIRST_REFLOW bit set), we pick an (arbitrary) 10x10
device pixel size, and initialize the page with that viewport.

Then, eventually, the frame gets laid out to the correct size and fires
a resize event.

If we have container queries around, we need to lay out the page while
styling, which causes the layout to happen before the script blocker
checkpoint, and thus the viewport to get initialized with the right size
to begin with.

This generally shouldn't be bad, but google chat at least seems to rely
on this resize event (and the divergence being caused by container
queries is rather unfortunate).

For now, do the low risk fix of always using the "initial" subdoc frame
size to show the viewer.

We should ideally sort this out better. Even our "good" behavior is
quite bizarre (e.g, I'd expect going from display: block to none to
trigger a resize event and the viewport to go back to 0... As you noted,
chrome's inner layout sizes do change when the frame is display: none).

But it seems worth to land this at least in the interim.

Differential Revision: https://phabricator.services.mozilla.com/D233399

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1935189
gecko-commit: 0c612ed5d669c157a34c24d0c7df4b7f8ccd5fe4
gecko-reviewers: dholbert
  • Loading branch information
emilio authored and moz-wptsync-bot committed Jan 8, 2025
1 parent 2ac6e88 commit 3567a89
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
19 changes: 19 additions & 0 deletions css/css-contain/container-iframe-resize-events-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html class="reftest-wait">
<meta charset="utf-8">
<title>CSS test reference</title>
<div>
<iframe src="./support/count-resizes.html" style="display: none"></iframe>
</div>
<script>
addEventListener("load", () => {
let frame = document.querySelector("iframe");
frame.style.display = "";
frame.getBoundingClientRect();
requestAnimationFrame(() => {
requestAnimationFrame(() => {
document.documentElement.className = "";
});
});
});
</script>
24 changes: 24 additions & 0 deletions css/css-contain/container-iframe-resize-events.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html>
<html class="reftest-wait">
<meta charset="utf-8">
<title>Containers don't affect the amount of resize events an iframe gets</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:[email protected]">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-conditional-5/#propdef-container-type">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1935189">
<link rel="match" href="container-iframe-resize-events-ref.html">
<div style="container-type: inline-size;">
<iframe src="./support/count-resizes.html" style="display: none"></iframe>
</div>
<script>
addEventListener("load", () => {
let frame = document.querySelector("iframe");
frame.style.display = "";
frame.getBoundingClientRect();
requestAnimationFrame(() => {
requestAnimationFrame(() => {
document.documentElement.className = "";
});
});
});
</script>
14 changes: 14 additions & 0 deletions css/css-contain/support/count-resizes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<div id="count">0</div>
<script>
let count = 0;
function updateResizeCount() {
document.getElementById("count").innerText = count;
}

updateResizeCount();
addEventListener("resize", () => {
count++;
updateResizeCount();
});
</script>

0 comments on commit 3567a89

Please sign in to comment.