Skip to content

fix(gatsby-image): add matchMedia to fix wrong aspect ratio and dimensions in art-directed image arrays#19887

Merged
pvdz merged 6 commits intogatsbyjs:masterfrom
timhagn:fix/add-match-media-to-art-direction
Dec 16, 2019
Merged

fix(gatsby-image): add matchMedia to fix wrong aspect ratio and dimensions in art-directed image arrays#19887
pvdz merged 6 commits intogatsbyjs:masterfrom
timhagn:fix/add-match-media-to-art-direction

Conversation

@timhagn
Copy link
Copy Markdown
Contributor

@timhagn timhagn commented Nov 30, 2019

Description

This PR introduces a matchMedia() query for fluid or fixed art-directed arrays.
This prevents retrieving the wrong image (the first from the art-direction stack ain't always the correct one) when ascertaining its aspectRatio or width & height respectively.

It adds tests for fluid or fixed art-directed stacks as well.

Of course this sadly only works during rendering in the browser, and falls back to the default first image from the array, but at least in the browser the correct image is chosen ; ).

Related Issues

Addresses #15189
Addresses a few of the pain points in ##13395
(And probably a few other issues ; )

Best,

Tim.

P.S.: Works quite well for me in gatsby-backrgound-image ; ).

@timhagn timhagn requested a review from a team November 30, 2019 15:35
@timhagn timhagn changed the title fix(gatsby-image): add matchMedia to fix wrong aspect ratio in art-directed image arrays fix(gatsby-image): add matchMedia to fix wrong aspect ratio and dimensions in art-directed image arrays Nov 30, 2019
Copy link
Copy Markdown
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've left some comments. Please have a look :)

Comment thread packages/gatsby-image/src/__tests__/index.js
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
change wording according to review

Co-Authored-By: Peter van der Zee <209817+pvdz@users.noreply.github.com>
@timhagn
Copy link
Copy Markdown
Contributor Author

timhagn commented Dec 2, 2019

Hi @pvdz,

thanks for the reviews, gonna continue attending them now. I just took the getCurrentSrcData() from gatsby-background-image and there is quite some use for just using fluid | fixed as an object (e.g. directly being able to pass (converted)props into the functions), but I see your point for gatsby-image. Am in the code : ).

Best,

Tim.

#done Adapted everything to your reviews / change requests and commented on the other two : ).

@timhagn timhagn requested a review from pvdz December 2, 2019 20:13
Copy link
Copy Markdown
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, thank you!

What's left is mostly about typing.

Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js Outdated
Comment thread packages/gatsby-image/src/index.js
Comment thread packages/gatsby-image/src/index.js Outdated
@timhagn
Copy link
Copy Markdown
Contributor Author

timhagn commented Dec 11, 2019

Hi @pvdz,

thanks again for the reviews and sorry that I didn't get back to you earlier, was just fully booked last week and got me a stomach bug over the weekend : (.
Gonna try getting your change requests in this week, though.

Best,

Tim.

@timhagn
Copy link
Copy Markdown
Contributor Author

timhagn commented Dec 12, 2019

Hi @pvdz,

while having a short break of both my bug & work and looking through your requests, I finally realize, why most of gatsby-image doesn't use JSDOC at all ^^.
But am at it.

Best, Tim.

@timhagn timhagn requested a review from pvdz December 12, 2019 13:31
@timhagn
Copy link
Copy Markdown
Contributor Author

timhagn commented Dec 12, 2019

Hi again, hope I now id change all comments and requests accordingly : ).

Best,

Tim.

@timhagn
Copy link
Copy Markdown
Contributor Author

timhagn commented Dec 12, 2019

Mkay. The starters_validate failing seems to have nothing to do with this PR, any ideas?

Best,

Tim.

EDIT: Oh, I forgot to merge in the other changes from upstream % ).

Copy link
Copy Markdown
Contributor Author

@timhagn timhagn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now everything should be according to your requests - else I'm just stripping out the JSDocs ; ).

Copy link
Copy Markdown
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all the issues and for creating this PR in the first place :D

@pvdz pvdz merged commit b3c000b into gatsbyjs:master Dec 16, 2019
@timhagn
Copy link
Copy Markdown
Contributor Author

timhagn commented Dec 16, 2019

Thanks @pvdz!

Hope I didn't get the JSDocs too wrong ^^. Glad something from gbi made it back to
gatbsy-image : ).

Best,

Tiim.

EDIT: Smiley split corrected; ).

raffishquartan pushed a commit to raffishquartan/gatsby that referenced this pull request Apr 28, 2026
…sions in art-directed image arrays (gatsbyjs#19887)

* fix query for wrong aspect ratio

* exchange fixed[0] to getCurrentSrcData({ fixed  }) to get correct dimensions

* Update packages/gatsby-image/src/index.js

change wording according to review

Co-Authored-By: Peter van der Zee <209817+pvdz@users.noreply.github.com>

* change functions according to reviews by @pvdz

* adapt jsdocs to change requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants