Skip to content

Commit

Permalink
✨ Discard long FCP and LCP
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Sep 13, 2021
1 parent 356c5a4 commit f9ef3d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DOM_EVENT, Duration, RelativeTime } from '@datadog/browser-core'
import { DOM_EVENT, Duration, ONE_MINUTE, RelativeTime } from '@datadog/browser-core'
import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../../../../core/test/specHelper'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'
import {
Expand Down Expand Up @@ -136,6 +136,16 @@ describe('trackFirstContentfulPaint', () => {
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_PAINT_ENTRY)
expect(fcpCallback).not.toHaveBeenCalled()
})

it('should not be present if it happens after 10 minutes', () => {
const { lifeCycle } = setupBuilder.build()

lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, {
...FAKE_PAINT_ENTRY,
startTime: (10 * ONE_MINUTE) as RelativeTime,
})
expect(fcpCallback).not.toHaveBeenCalled()
})
})

describe('largestContentfulPaint', () => {
Expand Down Expand Up @@ -181,6 +191,16 @@ describe('largestContentfulPaint', () => {

expect(lcpCallback).not.toHaveBeenCalled()
})

it('should not be present if it happens after 10 minutes', () => {
const { lifeCycle } = setupBuilder.build()

lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, {
...FAKE_LARGEST_CONTENTFUL_PAINT_ENTRY,
startTime: (10 * ONE_MINUTE) as RelativeTime,
})
expect(lcpCallback).not.toHaveBeenCalled()
})
})

describe('firstInputTimings', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
RelativeTime,
timeStampNow,
TimeStamp,
ONE_MINUTE,
} from '@datadog/browser-core'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
import { trackFirstHidden } from './trackFirstHidden'
Expand Down Expand Up @@ -76,7 +77,8 @@ export function trackFirstContentfulPaint(lifeCycle: LifeCycle, callback: (fcp:
if (
entry.entryType === 'paint' &&
entry.name === 'first-contentful-paint' &&
entry.startTime < firstHidden.timeStamp
entry.startTime < firstHidden.timeStamp &&
entry.startTime < 10 * ONE_MINUTE
) {
callback(entry.startTime)
}
Expand Down Expand Up @@ -118,7 +120,8 @@ export function trackLargestContentfulPaint(
if (
entry.entryType === 'largest-contentful-paint' &&
entry.startTime < firstInteractionTimestamp &&
entry.startTime < firstHidden.timeStamp
entry.startTime < firstHidden.timeStamp &&
entry.startTime < 10 * ONE_MINUTE
) {
lcpSizes.push({ timeStamp: timeStampNow(), startTime: entry.startTime, size: entry.size })
callback(entry.startTime)
Expand Down

0 comments on commit f9ef3d1

Please sign in to comment.