fix(gatsby-image): Remove native browser cache detection feature #26965
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
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 currentgatsby-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.gatsby-image
fallsback to Intersection Observer for lazy load.Related Issues
Fixes: #20126
Potential regression: #12254