Skip to content

Commit f4de21d

Browse files
authored
script: Do not store an initial content size in new ResizeObservers. (servo#40260)
ResizeObservers are supposed to have an initial 0x0 notification for targets that don't have a CSS layout box, but our default values were interfering with that. Testing: New passing tests. Fixes: part of servo#31182 Signed-off-by: Josh Matthews <[email protected]>
1 parent 8f38e26 commit f4de21d

File tree

4 files changed

+10
-20
lines changed

4 files changed

+10
-20
lines changed

components/script/dom/resizeobserver.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ fn create_and_populate_a_resizeobserverentry(
180180
// initialized with one reported size (zero).
181181
// The spec plans to store multiple reported sizes,
182182
// but for now there can be only one.
183-
observation.last_reported_sizes[0] =
183+
let last_reported_size =
184184
ResizeObserverSizeImpl::new(content_box_size.width(), content_box_size.height());
185+
if observation.last_reported_sizes.is_empty() {
186+
observation.last_reported_sizes.push(last_reported_size);
187+
} else {
188+
observation.last_reported_sizes[0] = last_reported_size;
189+
}
185190

186191
let content_rect = DOMRectReadOnly::new(
187192
window.upcast(),
@@ -307,17 +312,18 @@ struct ResizeObservation {
307312
impl ResizeObservation {
308313
/// <https://drafts.csswg.org/resize-observer/#dom-resizeobservation-resizeobservation>
309314
pub(crate) fn new(observed_box: ResizeObserverBoxOptions) -> ResizeObservation {
310-
let size_impl = ResizeObserverSizeImpl::new(0.0, 0.0);
311315
ResizeObservation {
312316
observed_box,
313-
last_reported_sizes: vec![size_impl],
317+
last_reported_sizes: vec![],
314318
state: Default::default(),
315319
}
316320
}
317321

318322
/// <https://drafts.csswg.org/resize-observer/#dom-resizeobservation-isactive>
319323
fn is_active(&self, target: &Element) -> bool {
320-
let last_reported_size = self.last_reported_sizes[0];
324+
let Some(last_reported_size) = self.last_reported_sizes.first() else {
325+
return true;
326+
};
321327
let box_size = calculate_box_size(target, &self.observed_box);
322328
box_size.width() != last_reported_size.inline_size() ||
323329
box_size.height() != last_reported_size.block_size()

tests/wpt/meta/resize-observer/notify.html.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,3 @@
88

99
[test6: inline element notifies once with 0x0.]
1010
expected: FAIL
11-
12-
[test11: display:none element should be notified]
13-
expected: FAIL
14-
15-
[test12: element sized 0x0 should be notified]
16-
expected: FAIL

tests/wpt/meta/resize-observer/observe.html.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@
2020
[test14: observe the same target but using a different box should override the previous one]
2121
expected: FAIL
2222

23-
[test16: observations fire once with 0x0 size for non-replaced inline elements]
24-
expected: FAIL
25-
2623
[test17: Box sizing snd Resize Observer notifications]
2724
expected: FAIL
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
[svg-with-css-box-001.html]
2-
expected: TIMEOUT
32
[test0: observe `foreignObject` SVG in HTML document]
43
expected: FAIL
5-
6-
[test1: observe inline SVG in HTML]
7-
expected: FAIL
8-
9-
[guard]
10-
expected: NOTRUN

0 commit comments

Comments
 (0)