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(gatsby-image): Remove native browser cache detection feature #26965

Conversation

polarathene
Copy link
Contributor

@polarathene polarathene commented Sep 20, 2020

Description

imgCached is presently only implemented for IntersectionObserver fallback, this method will always be falsey in Firefox and always truthy in Safari, other browsers when using the IO render path work correctly.

Safari is the primary browser that defaults to IO (native lazy load is available as an experimental feature toggle), and while imgCached can be implemented to support native lazy loading too, Safari is likely to remain buggy, so this feature is being removed.

There has been no complaints regarding it's omission with Firefox and Chrome native lazy load support that has been available for a reasonable amount of time now.


The handleRef() method has also been slightly refactored. Better for any future handling without IO, and for Art Directed images using IO.

This PR uses a portion from my Image cache improvements PR, slightly modified to remove the imgCached handling that brought the feature to native image lazy load (at least for blink browsers). There has been various reports / confirmations of Safari mishandling this feature.

Note: This PR has not been thoroughly tested. It should only affect browsers that use IntersectionObserver, and since the majority for that is Safari, it should resolve the reported bug. The latest Safari 14 release from this month keeps img native lazy loading as an experimental toggle feature, this will continue to be an issue for a while longer without this PR.

Warning: imgCached was originally introduced by this PR to address this issue, avoiding a placeholder flicker for an already cached image. I do not have access to Safari to reproduce, nor have I verified if that is an issue for Chrome/Firefox with current gatsby-image.

TL;DR

Safari mishandles a feature that Chrome used to benefit from. It's been reverted to remove the rendering bug.

  • imgCached is broken for Safari users. That feature was added before native lazy load, only Intersection Observer render path uses it.
  • Safari is the dominant browser where gatsby-image fallsback to Intersection Observer for lazy load.

Related Issues

Fixes: #20126

Potential regression: #12254

Presently only implemented for IntersectionObserver fallback, this method will always be falsey in Firefox and always truthy in Safari, other browsers when using the IO render path work correctly. Safari is the primary browser that defaults to IO (native lazy load is available as an experimental feature toggle), and while `imgCached` can be implemented to support native lazy loading too, Safari is likely to remain buggy, so this feature is being removed. There has been no complaints regarding it's omission with Firefox and Chrome native lazy load support that has been available for a reasonable amount of time now.

---

The `handleRef()` method has also been slightly refactored. Better for any future handling without IO, and for Art Directed images using IO.
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 20, 2020
@polarathene polarathene changed the title fix(gatsby-image): Remove imgCached feature fix(gatsby-image): Remove native browser cache detection feature Sep 21, 2020
It should just be `isVisible`, that will make `<picture>` available on the DOM to start downloading the image, and `imgLoaded` will be set once that image has finished loading.
Don't override the `fadeIn` state, `imgCached` handles this purpose. `imgLoaded` would also be true in this event. `seenBefore` should only be valid in the browser after hydration phase, initial render should therefore still match SSR.

Re-worded comments for maintainers.
@polarathene polarathene force-pushed the fix/gatsby-image-imgcached-safari branch from 2b9da32 to f20d6f9 Compare September 21, 2020 00:50
@LekoArts LekoArts added status: needs core review Currently awaiting review from Core team member topic: media Related to gatsby-plugin-image, or general image/media processing topics and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Sep 21, 2020
@wardpeet
Copy link
Contributor

wardpeet commented Nov 9, 2020

Closing, this is fixed in our new gatsby-plugin-image component. Thank you for your contribution! <3

@wardpeet wardpeet closed this Nov 9, 2020
@Anmol368
Copy link

Anmol368 commented Dec 1, 2020

#26965 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs core review Currently awaiting review from Core team member topic: media Related to gatsby-plugin-image, or general image/media processing topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The placeholder image in "gatsby-image" does not fade on Safari, again
4 participants