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

feat(gatsby-image): Add gatsby-image/withIEPolyfill export with object-fit/position support #12681

Merged
merged 8 commits into from
Mar 26, 2019

Conversation

ooloth
Copy link
Contributor

@ooloth ooloth commented Mar 19, 2019

Description

This PR will allow users who want object-fit/object-position support in IE to simply import Img from "gatsby-image/withIEPolyfill" instead of importing directly from "gatsby-image".

Please feel free to review the PR and let me know if the implementation can be improved.

The /withIEPolyfill version of gatsby-image currently does the following:

  1. Checks if the browser supports the object-fit/position CSS properties.
    a. If yes, no polyfill is loaded.
    b. If no, the object-fit-images polyfill is imported and called.
  2. Wraps gatsby-image in a component that passes the new objectFit and objectPosition prop values to the polyfill implementation (which requires a weird font-family hack).

New props

To make the implementation simple, I've added new objectFit and objectPosition props that will need to be used to pass the corresponding values to the polyfill. This is to avoid a scenario where a user attempts to set these values in a way we can't pass to the polyfill (e.g. via an external CSS stylesheet) and doesn't understand why the polyfill isn't working. Let me know if this API can be improved.

Loading polyfill in /withIEPolyfill/index.js

I opted to load the object-fit-images polyfill directly in withIEPolyfill/index.js rather than in gatsby-browser.js. If anyone knows of a better way to approach this, please let me know and feel free to make improvements.

Polyfill repo has been archived

I was surprised to see that the object-fit-images repo has recently been archived by its owner. It still works, but if anyone is concerned about this or knows of a reliable alternative polyfill, please let me know.

Docs to be updated once implementation is finalized

Once we've settled on the API for this /withIEPolyfills component, a brief explanation will need to be added to the gatsby-image docs. I held off on adding one for now in case we end up changing the API.

Related Issues

Fixes #4021.

@wardpeet
Copy link
Contributor

this is great!

Copy link
Contributor

@jonlow jonlow left a comment

Choose a reason for hiding this comment

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

Looks great 💪

@wardpeet
Copy link
Contributor

I updated the code a bit to accept an external ref as well. I'm going to test this that it doesn't break anything and get this merged tomorrow! 🎉 Thanks for all the hard work.

@ooloth
Copy link
Contributor Author

ooloth commented Mar 25, 2019

Love it! Thanks for the improvements. 👍

@wardpeet
Copy link
Contributor

pushed the latest fix, ref handling is ugly but changing forwardRef inside gatsby-image would be a breaking change.

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

Let's ship this when tests pass!

@ooloth
Copy link
Contributor Author

ooloth commented Mar 26, 2019

Sounds great! Thanks for guiding it over the finish line.

@wardpeet wardpeet changed the title Add gatsby-image/withIEPolyfill export with object-fit/position support chore(gatsby-image): Add gatsby-image/withIEPolyfill export with object-fit/position support Mar 26, 2019
@wardpeet wardpeet changed the title chore(gatsby-image): Add gatsby-image/withIEPolyfill export with object-fit/position support feat(gatsby-image): Add gatsby-image/withIEPolyfill export with object-fit/position support Mar 26, 2019
@wardpeet wardpeet merged commit 4b9b6a1 into gatsbyjs:master Mar 26, 2019
@ooloth ooloth deleted the topics/gatsby-image-with-ie-polyfill branch March 26, 2019 14:51
@lannonbr
Copy link
Contributor

Awesome to see this merged in! 🎉

Is it possible to append the docs for gatsby-image about this new feature if it hasn't already? @ooloth

ooloth added a commit that referenced this pull request Mar 26, 2019
Add instructions for using `gatsby-image/withIEPolyfill` as implemented by #12681.
@ooloth
Copy link
Contributor Author

ooloth commented Mar 26, 2019

Absolutely!

I just submitted PR #12869, which adds instructions to the gatsby-image README.

Feel free to improve it as needed.

marcysutton pushed a commit that referenced this pull request Mar 29, 2019
* Update README.md

Add instructions for using `gatsby-image/withIEPolyfill` as implemented by #12681.

* Update packages/gatsby-image/README.md

Prompt the user to include an alt attribute, even if empty, for accessibility.

Co-Authored-By: ooloth <hello@michaeluloth.com>

* Add line breaks

Trying to guess what issues Prettier is seeing while my computer is away for repairs...

* chore: format
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.

None yet

4 participants