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

Toolbar audit incorrectly flag images as above the fold #12993

Open
1 task done
Kynson opened this issue Jan 16, 2025 · 2 comments · May be fixed by #12998
Open
1 task done

Toolbar audit incorrectly flag images as above the fold #12993

Kynson opened this issue Jan 16, 2025 · 2 comments · May be fixed by #12998
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: toolbar Related to dev toolbar (scope)

Comments

@Kynson
Copy link

Kynson commented Jan 16, 2025

Astro Info

Astro                    v5.1.7
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The toolbar audit is flagging images that is below the fold when the following conditions are meet:

  1. The body element is not scrollable (window.scrollY always 0), e.g. image inside a scroll container
  2. A DOM mutation is made when the image is visible, i.e. seems to "above the fold" (required as the toolbar will only rerun the audit when there is a DOM mutation)

The fix #11617 does not seem to handle this situation, as window.scrollY is always 0 when the body is not the scroll container.
While the following fix mentioned in #10891 handle this correctly:

let element = htmlElement
let totalOffsetTop = 0
while (element) {
	totalOffsetTop += element.offsetTop
	element = element.offsetParent as HTMLElement
}
if (totalOffsetTop > window.innerHeight) return false;

What's the expected result?

The image should not be marked as above the fold

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-njrp6cag

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 16, 2025
@florian-lefebvre florian-lefebvre added - P3: minor bug An edge case that only affects very specific usage (priority) feat: toolbar Related to dev toolbar (scope) and removed needs triage Issue needs to be triaged labels Jan 16, 2025
@florian-lefebvre
Copy link
Member

@Kynson do you want to submit a PR for it?

@Kynson
Copy link
Author

Kynson commented Jan 17, 2025

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: toolbar Related to dev toolbar (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants