Skip to content

Conversation

@0x15f
Copy link
Contributor

@0x15f 0x15f commented May 10, 2022

Description

By default all img tags rendered using the Image component provided by Hydrogen have a loading attribute of lazy. This is not ideal for images that are above the fold as it can/will delay the FCP (image below)

image

This pull request adds loading as a prop that can be passed to any image/media component with a fallback to the lazy default. Currently specifying this property using passThroughProps results in two loading attributes on the img element––the browser takes the first and lazily loads the image.

This same functionality is covered (much better) by the proposal in #1223. However, Shopify is pushing Plus Merchants to build on Hydrogen prior to the production-ready rollout of the framework and this will/is affect(ing) anyone going to/already in production :).

Additional context


Before submitting the PR, please make sure you do the following:

  • Read the Contributing Guidelines
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123)
  • Update docs in this repository according to your change
  • Run yarn changeset add if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning

@0x15f 0x15f changed the title Support optional loadingprop on Image component Support optional loading prop on Image component May 10, 2022
@frehner
Copy link
Contributor

frehner commented May 10, 2022

If we change loading to priority here, as outlined in #1223, then this should be good!

Also, if you don't mind running yarn changeset add as a patch update then this will be ready to go. Thanks!

@elisenyang FYI

@0x15f 0x15f changed the title Support optional loading prop on Image component Support optional priority prop on Image component May 11, 2022
@0x15f
Copy link
Contributor Author

0x15f commented May 11, 2022

If we change loading to priority here, as outlined in #1223, then this should be good!

Also, if you don't mind running yarn changeset add as a patch update then this will be ready to go. Thanks!

@elisenyang FYI

The change has been made, documentation updated, and changelog added!

@frehner
Copy link
Contributor

frehner commented May 11, 2022

Just enabled the CI checks to run; looks like Prettier is complaining. You should be able to run yarn format to fix that.

It may also be worth checking on your side of things if yarn test passes.

@0x15f
Copy link
Contributor Author

0x15f commented May 11, 2022

Just enabled the CI checks to run; looks like Prettier is complaining. You should be able to run yarn format to fix that.

It may also be worth checking on your side of things if yarn test passes.

Strange, yarn format is not applying any changes in my environment, likely my git config with whitespace or related. Prettiers complaints are resolved. All tests are passing.

@frehner
Copy link
Contributor

frehner commented May 11, 2022

Just enabled the CI checks to run; looks like Prettier is complaining. You should be able to run yarn format to fix that.
It may also be worth checking on your side of things if yarn test passes.

Strange, yarn format is not applying any changes in my environment, likely my git config with whitespace or related. Prettiers complaints are resolved. All tests are passing.

I think @mcvinci 's changes may have fixed the formatting issues. In any case, I had to approve the CI jobs to run again (I thought once approved they would keep going, but I guess not?) and if they pass I'll merge!

@frehner frehner merged commit 07866e8 into Shopify:v1.x-2022-07 May 11, 2022
@frehner
Copy link
Contributor

frehner commented May 11, 2022

Thank you @0x15f !

@frehner frehner mentioned this pull request May 13, 2022
7 tasks
@frehner
Copy link
Contributor

frehner commented May 16, 2022

@0x15f Just a heads up, after thinking about it we decided that it didn't make sense to have a separate prop that does exactly what the HTML loading attribute does, and it would be confusing to have them both (e.g. what if they are set to different values? Why deviate from the HTML spec? etc.). So in #1271 I removed priority and just had it be loading

@0x15f
Copy link
Contributor Author

0x15f commented May 16, 2022 via email

This was referenced Jun 7, 2022
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.

3 participants