-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
layout: Improve sizing for inline SVG #38603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🔨 Triggering try run (#16888906752) for Linux (WPT) |
🔨 Triggering try run (#16889221764) for Linux (WPT) |
Test results for linux-wpt from try job (#16888906752): Flaky unexpected result (24)
Stable unexpected results that are known to be intermittent (24)
Stable unexpected results (49)
|
|
Test results for linux-wpt from try job (#16889221764): Flaky unexpected result (17)
Stable unexpected results that are known to be intermittent (17)
Stable unexpected results (49)
|
|
🔨 Triggering try run (#16890802592) for Linux (WPT) |
Test results for linux-wpt from try job (#16890802592): Flaky unexpected result (16)
Stable unexpected results that are known to be intermittent (20)
Stable unexpected results (56)
|
|
🔨 Triggering try run (#16891994262) for Linux (WPT) |
Test results for linux-wpt from try job (#16891994262): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (20)
Stable unexpected results (3)
|
|
🔨 Triggering try run (#16892654623) for Linux (WPT) |
Test results for linux-wpt from try job (#16892654623): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (18)
Stable unexpected results (27)
|
🔨 Triggering try run (#16893353174) for Linux (WPT) |
Test results for linux-wpt from try job (#16893353174): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (18)
|
✨ Try run (#16893353174) succeeded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
|
||
match attr.local_name() { | ||
&local_name!("width") | &local_name!("height") | &local_name!("viewBox") => { | ||
self.upcast::<Node>().dirty(NodeDamage::Other); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to explicitly dirty the node here? Based on my previous testing, the reflow happens after mutation even when the node is not dirtied here, but I admit I'm not sure where and how that reflow is initiated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried and it wasn't updating. Dirtying is consistent with components/script/dom/htmlcanvaselement.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for me without dirtying the element:
<!DOCTYPE html>
<style>
svg {
background-color: red;
}
</style>
<body>
<svg height="100" width="100">
<rect width="100" height="100" x="0" y="0" fill="blue" />
</svg>
<input type="button" id="clickBtn" value="Click Me" />
</body>
<script>
let state = false;
let svg = document.getElementsByTagName('svg')[0]
window.clickBtn.addEventListener("click", () => {
state = !state;
if (state) {
svg.setAttribute("width", "200");
} else {
svg.setAttribute("width", "100");
}
})
</script>
Are there other cases of mutation that this test html doesn't account for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't update without dirtying:
<!DOCTYPE html>
<svg height="100" width="100" style="border: solid"></svg>
<script>
setTimeout(() => {
document.querySelector("svg").setAttribute("width", "200");
}, 1e3);
</script>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I guess the reflow in my example might have been triggered by something else e.g due to the input event handling. I guess we should then dirty the node unconditionally here, as other attributes on the root (such as style
) are also serialized into the cached data url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've triggered a try run with a patch to move the dirtying code into invalidate_cached_subtree
https://github.com/servo/servo/actions/runs/16906961737
I can push it to this branch when if it passes the WPT suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should then dirty the node unconditionally here, as other attributes on the root (such as
style
) are also serialized into the cached data url.
I've pused 9dfb577 to do this.
🔨 Triggering try run (#16904355402) for Linux (WPT) |
Test results for linux-wpt from try job (#16904355402): Flaky unexpected result (21)
Stable unexpected results that are known to be intermittent (18)
|
✨ Try run (#16904355402) succeeded. |
The metadata provided by usvg has unreliable sizes. Ignore it, and rely on the `width`, `height` and `viewBox` attributes instead. Note that inline SVG with a natural aspect ratio but no natural sizes should stretch to the containing block. This is left for a follow-up. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
The metadata provided by usvg has unreliable sizes. Ignore it, and rely on the
width
,height
andviewBox
attributes instead.Note that inline SVG with a natural aspect ratio but no natural sizes should stretch to the containing block. This is left for a follow-up.
Bumps Stylo to servo/stylo#229
Testing: Improves several WPT.