-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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-plugin-image): object-fit polyfill for IE #29072
Conversation
052ab71
to
ec35794
Compare
My main question would be, why not load it as part of gatsby-browser? It becomes part of the app bundle so we are sure that it's always loaded. We don't have to do any ref checks in the react components |
As in load it unconditionally? Right now it's only loading it for IE. If I load it conditionally in gatsby-browser, it'll still need the check before it's called in case it hasn't finished loading. |
You could put this in export const onClientEntry = () => {
// Object-fit/Object-position polyfill for gatsby-image (IE)
const testImg = document.createElement(`img`)
if (
typeof testImg.style.objectFit === `undefined` ||
typeof testImg.style.objectPosition === `undefined`
) {
return import(
/* webpackChunkName: "objectFitPolyfill" */ `objectFitPolyfill`
).then(mod => mod.default())
}
} |
Right, but I still need to apply it inside the component, because otherwise it won't catch any images that aren't in the DOM at the point it loads. This is why I'm calling it on individual components rather than globally. |
You're correct! We need to run on a single ref, I thought we had to run it once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it's fine to go forward with this version as both work and it's a matter of preference.
Co-authored-by: Ward Peeters <[email protected]>
* wip * Update polyfill * Add webpackChunkName Co-authored-by: Ward Peeters <[email protected]> * Format Co-authored-by: Ward Peeters <[email protected]>
Lazy-loads a polyfill for
object-fit
andobject-position
if the browser doesn't support them (so IE11).[ch20513]