Skip to content

perf(scripts): replace window.innerWidth with matchMedia to avoid forced reflow#620

Open
shsteimer wants to merge 1 commit into
mainfrom
avoid-forced-reflow
Open

perf(scripts): replace window.innerWidth with matchMedia to avoid forced reflow#620
shsteimer wants to merge 1 commit into
mainfrom
avoid-forced-reflow

Conversation

@shsteimer
Copy link
Copy Markdown
Contributor

@shsteimer shsteimer commented May 12, 2026

Summary

  • Replaces window.innerWidth >= 900 with window.matchMedia('(min-width: 900px)').matches in the eager load path of scripts.js
  • window.innerWidth forces a synchronous layout reflow; matchMedia reads from the pre-computed style state and does not

Why

Lighthouse / Chrome DevTools flags window.innerWidth as a forced-reflow source. See: https://developer.chrome.com/docs/performance/insights/forced-reflow

While i'm not convinced it's a real problem, I can envision scenarios where it could be, and I see no downside to eliminating the warning.

Preview

https://avoid-forced-reflow--aem-boilerplate--adobe.aem.live

🤖 Generated with Claude Code

…ced reflow

window.innerWidth forces a layout reflow each time it is read. matchMedia
reads from the pre-computed style state without triggering layout, eliminating
the Lighthouse forced-reflow warning on the eager load path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aem-code-sync
Copy link
Copy Markdown

aem-code-sync Bot commented May 12, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits

@aem-code-sync
Copy link
Copy Markdown

aem-code-sync Bot commented May 12, 2026

Page Scores Audits Google
📱 / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

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.

1 participant