fix(browser): filter implausible LCP values#20338
Conversation
size-limit report 📦
|
Lms24
left a comment
There was a problem hiding this comment.
Gonna approve, I think this is a good short-term fix/improvement
Co-Authored-By: GPT-5 <noreply@anthropic.com>
8aa994f to
1063983
Compare
There was a problem hiding this comment.
Pull request overview
Adds an LCP plausibility guard in browser-utils to prevent reporting obviously incorrect Largest Contentful Paint values (e.g. > 60s), aiming to improve the quality of browser LCP metrics/spans.
Changes:
- Introduce
MAX_PLAUSIBLE_LCP_DURATIONandisValidLcpMetric(...)for LCP plausibility filtering. - Apply the plausibility check to pageload LCP measurements and standalone LCP spans.
- Add unit tests covering valid/invalid LCP values and standalone LCP span emission.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/browser-utils/test/metrics/lcp.test.ts | Adds unit tests for the new LCP validation helper and standalone LCP span guard behavior. |
| packages/browser-utils/src/metrics/lcp.ts | Defines plausibility threshold + validation helper; uses it when collecting/sending standalone LCP spans. |
| packages/browser-utils/src/metrics/browserMetrics.ts | Uses the new validation helper to filter implausible LCP values when recording pageload measurements. |
Comments suppressed due to low confidence (1)
packages/browser-utils/src/metrics/browserMetrics.ts:292
- The new LCP plausibility filter in
_trackLCPchanges pageload measurement behavior but isn't covered by unit tests. Since there are existing tests formetrics/browserMetrics(e.g.packages/browser-utils/test/browser/browserMetrics.test.ts), consider adding a focused test which verifies that values >MAX_PLAUSIBLE_LCP_DURATIONdo not set thelcpmeasurement / entry, while plausible values still do.
function _trackLCP(): () => void {
return addLcpInstrumentationHandler(({ metric }) => {
const entry = metric.entries[metric.entries.length - 1];
if (!entry || !isValidLcpMetric(metric.value)) {
return;
}
_measurements['lcp'] = { value: metric.value, unit: 'millisecond' };
_lcpEntry = entry as LargestContentfulPaint;
}, true);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 128ab47. Configure here.
LCP is a paint time — 0ms is physically impossible. Accepting it let the uninitialized default (0) leak through as a spurious span when the only observed LCP value was filtered out as implausibly high. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Summary