Proposed target bug: Bug 1929151 Related bugs: 1993701, 1204850, 1409529
Suggested summary if a new bug is preferred:
Firefox resolves dimensionless SVG <img> to 0x0 inside width:fit-content parent when the img has width:100% and max-width
Suggested Bugzilla comment for Bug 1929151:
This looks like another reduced testcase for the same underlying issue, but affecting `width: fit-content` on the parent instead of `min-width` / `max-content` on the image itself.
Reduced testcase attached:
firefox-fit-content-shadow.html
What it does:
- Uses a dimensionless external-style SVG image (natural size ends up 300x104 in both browsers)
- Places it inside a parent link with `display:block; width:fit-content`
- Gives the `<img>` `width:100%; max-width:92px`
- Repeats the same case in regular DOM and in shadow DOM
- Includes control cases where the parent width is explicit `92px`
Observed results:
- Chrome 145:
- DOM + fit-content: link 92x32, img 92x32
- Shadow + fit-content: link 92x32, img 92x32
- Firefox 147:
- DOM + fit-content: link 0x0, img 0x0
- Shadow + fit-content: link 0x0, img 0x0
- In both browsers, the explicit-width control cases render as 92x32.
- In both browsers, the image reports `naturalWidth=300` and `naturalHeight=104`.
So this does not seem to be a shadow-DOM issue. Firefox specifically collapses the fit-content cases to zero during intrinsic sizing.
Why this looks spec-wrong:
- CSS Sizing 3 §5.2.1 says that for replaced elements, a cyclic percentage preferred size is treated as the property's initial value for max-content contribution calculations.
- In this testcase, the image is replaced, `width:100%` is cyclic, and `max-width:92px` is non-cyclic.
- So the image's max-content contribution should not become 0 here. At minimum, it should remain constrained by its non-cyclic `max-width:92px`, not collapse to zero.
Relevant spec text:
- https://drafts.csswg.org/css-sizing-3/#intrinsic-contribution
- In particular the "Intrinsic Contributions of Percentage-Sized Boxes" rules:
- cyclic preferred/max size on replaced elements for max-content contribution: treat as initial value
- summary table in §5.2.1
Cross-browser measurements from automation:
{ "chrome": { "domFit": { "linkWidth": 92, "imgWidth": 92, "naturalWidth": 300, "naturalHeight": 104 }, "shadowFit": { "linkWidth": 92, "imgWidth": 92, "naturalWidth": 300, "naturalHeight": 104 } }, "firefox": { "domFit": { "linkWidth": 0, "imgWidth": 0, "naturalWidth": 300, "naturalHeight": 104 }, "shadowFit": { "linkWidth": 0, "imgWidth": 0, "naturalWidth": 300, "naturalHeight": 104 } } }
If helpful I can turn this into a WPT-style testcase as well.
Notes:
- The reduced testcase is at
/Users/damon/simulchrist/testcases/firefox-fit-content-shadow.html - Measured results are at
/Users/damon/simulchrist/testcases/firefox-fit-content-shadow-results.json