Fix SVG intrinsic sizing for replaced elements - #606
Merged
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
devin-ai-integration
Bot
force-pushed
the
devin/1784873193-svg-intrinsic-sizing
branch
from
August 4, 2026 15:11
408fba7 to
3df6c8e
Compare
Bumps usvg to 0.48.1 (with git patches for usvg's pending intrinsic_dimensions API and anyrender's usvg bump) and replaces the roxmltree attribute sniffing and re-parse hack in parse_svg_image.
devin-ai-integration
Bot
force-pushed
the
devin/1784873193-svg-intrinsic-sizing
branch
from
August 4, 2026 16:19
a08f3a0 to
7a72d91
Compare
SvgImageData now stores only the Arc<usvg::Tree>; intrinsic width/height and the viewBox ratio are derived on demand from Tree::intrinsic_dimensions, leaving room to resolve percentage dimensions against layout context in future.
…ng block For an inline <svg> element the width/height attributes are presentation attributes: absent attributes default to 100% and percentages resolve against the containing block. SVG loaded as an image keeps context-free intrinsic dimensions per CSS. Adds SvgImageData::resolved_width/height and feeds them into the replaced element attr_size for svg elements.
…l flow Absent width/height attributes on an inline <svg> element no longer default to 100% of the containing block (which broke bare <svg> elements). Instead, a replaced SVG with only an intrinsic aspect ratio uses the CSS2 stretch-fit width when the available width is definite, and keeps the default object size in shrink-to-fit contexts (floats, abspos).
dotmonkey
added a commit
to tti-inspirata/ebook_blitz
that referenced
this pull request
Aug 5, 2026
上游该 commit 依赖未发布的 usvg Tree::intrinsic_dimensions(仅存在于 DioxusLabs/resvg 临时分支)与配套的 anyrender_svg,靠 blitz workspace 的 [patch.crates-io] 兜住;而 ReaderEngine 以 root 身份构建时该 patch 被 cargo 忽略,直接编译失败。等上游 usvg 0.48.2 / anyrender_svg 发布后取消本 revert。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement CSS intrinsic sizing for SVG replaced elements instead of using
usvg::Tree::size()as the intrinsic dimensions in every case.SvgImageDatatracks absolute root dimensions separately from the rootviewBoxaspect ratio.intrinsic_size()resolves both declared dimensions, derives a missing dimension from the intrinsic ratio, and applies the CSS default object size (300x150) for ratio-only SVGs.This now uses
usvg::Tree::intrinsic_dimensions()— a new upstream API (branchDioxusLabs/resvg#devin/1785858271-intrinsic-dimensions, proposed for linebender/resvg) exposing the declared rootwidth/height/viewBoxwith percentages unresolved — instead of re-parsing the SVG XML with roxmltree. usvg is bumped to 0.48.1, whose viewBox-ratio missing-dimension fix (resvg#1045) also removes the previous inject-attribute-and-re-parse hack.Temporary
[patch.crates-io]entries pointusvg/anyrender/anyrender_svgat git branches until the upstream resvg PR lands+releases and DioxusLabs/anyrender#78 is released.WPT (css/css-flexbox, full local run)
flex-aspect-ratio-img-*, −1aspect-ratio-intrinsic-size-007.html)<svg viewBox=...>with no width/height, which per SVG spec should default towidth:100%but is now sized with the 300x150 default object size. Pre-existing in this PR before the usvg migration; needs separate handling of the root<svg>element's presentation-attribute defaults.Test Plan
cargo test -p blitz-dom svg_tests,cargo test -p blitz-tests --test svg_background_size,cargo clippy -p blitz-dom,cargo fmt --checkall pass.Link to Devin session: https://app.devin.ai/sessions/1372da3cbba94b90a9c63cad94bdbdc1
Requested by: @nicoburns
WPT results
15 newly passing, 0 newly failing (net +15).
Full diff (15 changed tests)
Generated by the WPT workflow.