question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gatsby-image is requesting each image 4 times in Safari

See original GitHub issue

Description

gatsby-image causes Safari (both iOS and macOS) to request the same image 4 times. To be sure that this isn’t something specific to my browser and machine I also tested this in an iOS Simulator for iOS Safari, on macOS Mojave with the latest Safari and also on a clean macOS Catalina Safari via Browserstack. They all behave the same way: The same image is requested and downloaded 4 times.

Chromium-based browsers don’t seem to have issues here.

Interestingly though in Firefox there is similar but indeterministic behavior: In Firefox (75, macOS 10.15.4) the same image sometimes is requested 2 times and sometimes only once. This erratic behavior in Firefox led me to believe that this might be some sort of race condition, but I couldn’t find the culprit.

Steps to reproduce (for Safari)

  1. Create new gatsby site with the gatsby-starter-default
  2. Load the index page with Safari Dev Tools open and caching disabled
  3. Check the network tab to see that the same gatsby-astronaut.png is requested 4 times

Steps to reproduce (for Firefox)

  1. Create new gatsby site with the gatsby-starter-default
  2. Load the index page with Firefox Dev Tools open and caching disabled
  3. Check the network tab while reloading the page in quick succession to see that that the same gatsby-astronaut.png sometimes is requested once and sometimes twice.

Expected result

The browser should only load one image that works for the viewport.

Actual result

The browser instead loads the same image several times.

Screenshot

Bildschirmfoto 2020-04-26 um 14 02 55

Environment

System: OS: macOS 10.15.4 CPU: (12) x64 Intel® Core™ i7-8850H CPU @ 2.60GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 81.0.4044.122 Firefox: 75.0 Safari: 13.1 npmPackages: gatsby: ^2.20.25 => 2.20.25 gatsby-image: ^2.3.4 => 2.3.4 gatsby-plugin-manifest: ^2.3.5 => 2.3.5 gatsby-plugin-offline: ^3.1.4 => 3.1.4 gatsby-plugin-react-helmet: ^3.2.4 => 3.2.4 gatsby-plugin-sharp: ^2.5.6 => 2.5.6 gatsby-source-filesystem: ^2.2.4 => 2.2.4 gatsby-transformer-sharp: ^2.4.6 => 2.4.6

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kraynelcommented, Apr 30, 2020

After some digging, it seems there are known bugs (https://bugs.webkit.org/show_bug.cgi?id=177068 and https://bugs.webkit.org/show_bug.cgi?id=190031) in Safari: when creating a new picture with an image and source with JS, Safari incorrectly loads both srcset.

This probably explains the multiple calls.

https://github.com/facebook/react/issues/15215

I reproduced with this behavior outside of gatsby-image: image

1reaction
MartinGiancommented, Jul 14, 2020

Same for me, it affects the first ever page load but we suspect that it is causing some bounce rate, users don’t seem to like image flickering or wait 😅 .

It seems that the only option we have at the moment is wait for a fix.

Thanks for your quick response!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Gatsby Image plugin
The Gatsby Image plugin includes two image components: one for static and one for dynamic images. The simplest way to decide which you...
Read more >
Gatsby Changelog | 5.3.0
Speed Improvements for Image Processing. After updating gatsby-plugin-image and gatsby-plugin-sharp , you should see a considerate amount of time saved during ...
Read more >
A Guide to the Responsive Images Syntax in HTML - CSS-Tricks
This guide is about the HTML syntax for responsive images (and a little bit of CSS ... (as in, by the time a...
Read more >
How to improve gatsby image querying for specific images
In the way you are using your Image component, you are forced to query and fetch 600 images each time you request an...
Read more >
gatsby-background-image - npm package - Snyk
Snyk scans all the packages in your projects for vulnerabilities and provides ... gatsby-background-image, we found that it has been starred 262 times, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found