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: Strip out empty srcSet entries passed to renderFigure() #13

Merged

Conversation

joostdecock
Copy link
Contributor

Some of my images where not showing up, so I did some digging and
noticed that an array like this was passed to renderFigure():

[
  { aspectRatio: 0, srcSet: [], width: 1000 },
  { aspectRatio: 0, srcSet: [], width: 2000 },
  {
    aspectRatio: 1.4970059880239521,
    srcSet: [ [Object], [Object] ],
    width: 250
  },
  { aspectRatio: 1.5015015015015014, srcSet: [ [Object] ], width: 500 }
]

In renderFigure() we use srcSets.shift().srcSet which in a case like
this means the img tag will be skipped.

This filters the sources list to only those that have an actual srcSet
value. The array passed to renderFigure() becomes:

[
  {
    aspectRatio: 1.4970059880239521,
    srcSet: [ [Object], [Object] ],
    width: 250
  },
  { aspectRatio: 1.5015015015015014, srcSet: [ [Object] ], width: 500 }
]

Some of my images where not showing up, so I did some digging and
noticed that an array like this was passed to `renderFigure()`:

```js
[
  { aspectRatio: 0, srcSet: [], width: 1000 },
  { aspectRatio: 0, srcSet: [], width: 2000 },
  {
    aspectRatio: 1.4970059880239521,
    srcSet: [ [Object], [Object] ],
    width: 250
  },
  { aspectRatio: 1.5015015015015014, srcSet: [ [Object] ], width: 500 }
]
```

In `renderFigure()` we use `srcSets.shift().srcSet` which in a case like
this means the img tag will be skipped.

This filters the sources list to only those that have an actual srcSet
value. The array passed to `renderFigure()` becomes:

```js
[
  {
    aspectRatio: 1.4970059880239521,
    srcSet: [ [Object], [Object] ],
    width: 250
  },
  { aspectRatio: 1.5015015015015014, srcSet: [ [Object] ], width: 500 }
]
```
@florianeckerstorfer florianeckerstorfer merged commit c456575 into florianeckerstorfer:main Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants