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.

Invalid empty srcSet attribute in SSR

See original GitHub issue

Describe the bug We’re attempting to use this library with Gatsby. In SSR (server-side rendering), an empty srcSet="" attribute is rendered on the <img tag. This is bad because:

a) an empty srcset attribute is invalid, and b) This may cause the browser to block rendering and attempt to load the img based on srcset, completely defeating the purpose of image-lazyloading.

Here’s an example of the minified output:

<img style="height:100%;width:100%;visibility:hidden;position:absolute;top:0;left:0" alt="retropie" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" srcSet="" data-src="https://howchoo.com/media/mt/a5/yz/mta5yzzjoweg_md.jpeg" data-srcset="https://howchoo.com/media/mt/a5/yz/mta5yzzjowet.jpeg 200w, https://howchoo.com/media/mt/a5/yz/mta5yzzjoweg_xs.jpeg 360w, https://howchoo.com/media/mt/a5/yz/mta5yzzjowem.jpeg 414w, https://howchoo.com/media/mt/a5/yz/mta5yzzjoweg_md.jpeg 768w, https://howchoo.com/media/mt/a5/yz/mta5yzzjoweg.jpeg 900w, https://howchoo.com/media/mt/a5/yz/mta5yzzjowel.jpeg 1440w" sizes="(max-width: 200px) 200px, (max-width: 360px) 360px,(max-width: 414px) 414px, (max-width: 768px) 768px,(max-width: 900px) 900px, (max-width: 1440px) 1440px, 900px"/>

Note srcSet="" above.

To Reproduce Steps to reproduce the behavior:

  1. Use react-simple-img normally
  2. Run SSR (for gatsby, using gatsby build && gatsby serve)
  3. Observe the HTML output contains an empty srcSet="" attribute on the <img> tag.

Expected behavior I expect that attribute to not exist in the SSR HTML.

Screenshots N/A

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • react-simple-img@2.3.7

Thanks for the excellent library! I’d be happy to help test a fix if needed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Dec 11, 2019

awesome thanks @ZLevine I will release the patch soon.

1reaction
bluebill1049commented, Dec 4, 2019

any chance you can create a PR for this? I am pretty busy with another OS project at the moment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid empty srcSet attribute in SSR · Issue #85 - GitHub
I submitted a PR with a fix. By setting the srcSet prop value to null if it's not cached, the prop is omitted...
Read more >
Server Side Rendering, Lazy Loading Responsive Images ...
On pages with tags, I'm using both src, srcSet and sizes attributes on img to allow the client to choose an appropriate image...
Read more >
How to fix: Bad value for attribute “srcset” on element “source”
Ensure that this attribute contains only digits. The value specified for a width attribute in CSS is not valid. The width CSS property...
Read more >
Image - Chakra UI
Image. The Image component is used to display images. Image composes Box so you can use all the style props and add responsive...
Read more >
next/image - Next.js
A placeholder to use while the image is loading. Possible values are blur or empty . Defaults to empty . When blur ,...
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