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: audit incorrectly flagging images as above the fold (#10891) #11617

Merged
merged 2 commits into from
Aug 5, 2024
Merged

fix: audit incorrectly flagging images as above the fold (#10891) #11617

merged 2 commits into from
Aug 5, 2024

Conversation

abubakriz
Copy link
Contributor

@abubakriz abubakriz commented Aug 4, 2024

Changes

  • Fixes Toolbar audit incorrectly flagging images as above the fold #10891

  • Previously used element.offsetTop to find the y position of the image, which does not work when the element parent has a position: relative property.

  • Instead, this uses element.getBoundingClientRect().y to get the real y position of the image.

  • There's one issue though. getBoundingClientRect returns the position relative to the user's viewport, not the absolute position.

  • So, add window.scrollY to the value, and you have the element's absolute position.

Testing

No new tests were added as this is a trivial fix.

Docs

No docs needed for this fix.

Previously used �lement.offsetTop to find the y position of the image, which does not work when the element parent has a position: relative property.
Instead, this uses �lement.getBoundingClientRect().y top get real y position of the image.
There's one issue though, which is that getBoundingClientRect returns the position relative to the user's viewport, not the absolute position.
So, add window.scrollY to the value to cancel that effect out, and you have the element's absolute position.

https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY
Copy link

changeset-bot bot commented Aug 4, 2024

🦋 Changeset detected

Latest commit: 5864c47

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 4, 2024
@Princesseuh Princesseuh merged commit 196092a into withastro:main Aug 5, 2024
13 checks passed
This was referenced Aug 5, 2024
@abubakriz abubakriz deleted the fix/below-above-fold-detection branch August 6, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toolbar audit incorrectly flagging images as above the fold
3 participants