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

Fixes for image sizes #74

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fixes for image sizes #74

wants to merge 3 commits into from

Conversation

riffbyte
Copy link
Contributor

  • Add previously missing explicit width and height for images (prevent CLS issues)
  • Add ability to pass custom sizes string, generate the srcset based on the sizes property

@riffbyte riffbyte self-assigned this Dec 27, 2023
Copy link
Contributor

@e1himself e1himself left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +6 to +7
expect(convertSizesToWidths('test string 123')).toEqual([]);
expect(convertSizesToWidths('test, 123')).toEqual([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it maybe throw instead? Just to not cover possible human mistakes?

Copy link
Contributor Author

@riffbyte riffbyte Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree it makes sense to throw 👍🏻

src/components/Media/Media.tsx Show resolved Hide resolved
image,
style,
title,
sizes = '(max-width: 992px) 800px, (max-width: 576px) 400px, 1200px',
Copy link
Contributor

@e1himself e1himself Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the order correct here? Should it not go from the lowest to the highest max-width values?

Suggested change
sizes = '(max-width: 992px) 800px, (max-width: 576px) 400px, 1200px',
sizes = '(max-width: 576px) 400px, (max-width: 992px) 800px, 1200px',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the order actually matters here, couldn't find anything pointing to that 🤔

Copy link
Contributor

@e1himself e1himself Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this in JSFiddle, and it seems they have to follow the lowest-to-highest order. Otherwise the smaller breakpoint following a larger one will be ignored.

Compare these two:

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.

2 participants