Don't use cached client_rect() when a reflow is needed (#31210)

Fixes #31195:

```js
element.style.width = "5px";
element.clientWidth; // 5
element.style.width = "15px";
element.clientWidth; // Was 5, now 15
```
This commit is contained in:
Oriol Brufau 2024-01-29 15:59:36 +01:00 committed by GitHub
parent 742d3ed97f
commit 38d9245726
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 30 deletions

View file

@ -3372,30 +3372,26 @@ impl<'a> SelectorsElement for DomRoot<Element> {
impl Element {
fn client_rect(&self) -> Rect<i32> {
let doc = self.node.owner_doc();
if let Some(rect) = self
.rare_data()
.as_ref()
.and_then(|data| data.client_rect.as_ref())
.and_then(|rect| rect.get().ok())
{
return rect;
if doc.needs_reflow().is_none() {
return rect;
}
}
let mut rect = self.upcast::<Node>().client_rect();
let in_quirks_mode = self.node.owner_doc().quirks_mode() == QuirksMode::Quirks;
let in_quirks_mode = doc.quirks_mode() == QuirksMode::Quirks;
if (in_quirks_mode &&
self.node.owner_doc().GetBody().as_deref() == self.downcast::<HTMLElement>()) ||
if (in_quirks_mode && doc.GetBody().as_deref() == self.downcast::<HTMLElement>()) ||
(!in_quirks_mode && *self.root_element() == *self)
{
let viewport_dimensions = self
.node
.owner_doc()
.window()
.window_size()
.initial_viewport
.round()
.to_i32();
let viewport_dimensions = doc.window().window_size().initial_viewport.round().to_i32();
rect.size = Size2D::<i32>::new(viewport_dimensions.width, viewport_dimensions.height);
}