What is the lighthouse bug about? - briefly
The Lighthouse bug is a documented defect in Google’s Lighthouse audit tool that can produce inaccurate performance scores when pages load dynamic content after the initial render. A fix for this issue is planned for upcoming releases.
What is the lighthouse bug about? - in detail
The lighthouse bug is a defect in Google’s Lighthouse auditing framework that produces inaccurate performance metrics under specific conditions. It occurs when the tool processes pages that contain dynamically generated content loaded after the initial page render. The script responsible for collecting timing data fails to wait for certain asynchronous events, causing the recorded First Contentful Paint (FCP) and Largest Contentful Paint (LCP) values to be lower than the actual user‑perceived times.
Typical symptoms include:
- FCP and LCP numbers that differ markedly from Chrome DevTools measurements on the same page.
- Inconsistent scores for “Performance” and “Best Practices” across repeated runs.
- Console warnings indicating “timing data unavailable” or “unexpected null values” during audits.
Root causes are traced to:
- Premature termination of the tracing session – the tracing API stops before all network requests settle.
- Incorrect handling of
requestIdleCallback
– callbacks scheduled after the trace are ignored, leaving out late‑loading elements. - Failure to observe
MutationObserver
events – DOM changes triggered by client‑side rendering are not captured.
Mitigation steps:
- Insert a
waitForIdle
hook in the audit configuration to extend the trace duration until all network activity ceases. - Enable the
skipAudits
flag for tests that focus on static content only, avoiding the bug’s trigger path. - Update to the latest Lighthouse version (≥ 10.2.0), where the bug is patched by deferring the trace stop until the
load
event fires and by incorporating a fallback timer for idle detection.
Resolution in the official repository involved:
- Refactoring the trace controller to monitor both network idle and DOM stability.
- Adding unit tests that simulate delayed script execution and verify metric accuracy.
- Publishing release notes that describe the change and advise developers to re‑run audits on affected pages.
Understanding these details allows developers to identify false‑positive performance reports, apply the appropriate configuration adjustments, and ensure that Lighthouse provides reliable data for optimization decisions.