Skip to content
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

fix: img SVGs with no dimensions not scaling #629

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

rpearce
Copy link
Owner

@rpearce rpearce commented Jul 8, 2024

Description

If an <img /> element has a src that is an SVG that has no width nor height defined, we got into a weird spot where the loaded element had naturalWidth and naturalHeight of 0. This can differ between browsers, but most notably in Firefox. In Firefox, since this is 0, the object fit calculations were dividing by zero, leading the scaling factor to go from its correct amount (scale to the browser window) to not scaling whatsoever and just centering the image on the screen at the same size it was rendered at. The fix here is to do what we do for other calculation functions and fallback to the image's rect measurements.

This also makes sure we use decoding="async" on test images to make sure we're always testing the laziest images possible!

If an `<img />` element has a `src` that is an SVG that has no `width`
nor `height` defined, we got into a weird spot where the loaded element
had `naturalWidth` and `naturalHeight` of `0`. This can differ between
browsers, but most notably in Firefox. In Firefox, since this is `0`,
the object fit calculations were dividing by zero, leading the scaling
factor to go from its correct amount (scale to the browser window) to
not scaling whatsoever and just centering the image on the screen at the
same size it was rendered at. The fix here is to do what we do for other
calculation functions and fallback to the image's rect measurements.
@rpearce rpearce added the bug label Jul 8, 2024
@rpearce rpearce self-assigned this Jul 8, 2024
@rpearce rpearce changed the title fix: img SVGs with no dimensions fix: img SVGs with no dimensions not scaling Jul 8, 2024
@rpearce rpearce merged commit ac7d491 into main Jul 8, 2024
2 checks passed
@rpearce rpearce deleted the fix/img-svg-src-no-dimensions branch July 8, 2024 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant