fix: alt text no longer cause images to render at wrong dimensions #146
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.
Description
Previously, if a user wished to add alt text to an image it would cause the image to be displayed at weird dimensions depending on which browser the user was using. This was due to two reasons: a) in some browsers, including alt text meant that empty images would render at dimensions other than
0x0
, and b) in some browsers, that the first render pass of this component (which renders an empty image) would cause an empty, invalid, image to render at dimensions other than0x0
.Rendering at
0x0
is important for this library to work out what the dimensions of the requested image should be. If the empty image renders at0x0
, this means that the user has not constrained the size of the image, and that a full-res image should be requested. If the empty image renders at anything other than0x0
, this means that the user has constrained the image in some way, and that we should only request an image for those dimensions.This PR fixes these problems in two ways. First, it only adds the alt text after the first render pass (or if in
aggressiveLoad
mode). Before the second render pass,alt
is empty. Second, the src for an empty image is a data-uri of a 1x1 transparent gif. Before now, the component rendered an invalid image (as it had no src), which caused browser behaviour to be undefined. Now, with the new src, the image is valid, and browsers render the image consistently.This fixes #41.
Bug Fix
fix(<area>): fixed bug #issue-number
Steps to Test
Review the tests in
test/integration/react-imgix.test.js
andtest/unit/react-imgix.test.js