Skip to content

Commit

Permalink
Remove FID wait timeout on OOB trace send. This gets sent at first un…
Browse files Browse the repository at this point in the history
…load now, so no need to add additional timeouts.
  • Loading branch information
bryanatkinson committed Nov 26, 2024
1 parent 865da93 commit 4b4d9ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 47 deletions.
24 changes: 0 additions & 24 deletions packages/performance/src/services/oob_resources_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,30 +250,6 @@ describe('Firebase Performance > oob_resources_service', () => {
);
});

it('waits for first input delay if polyfill is available', () => {
getIidStub.returns(MOCK_ID);
const api = Api.getInstance();
//@ts-ignore Assignment to read-only property.
api.onFirstInputDelay = stub();
setupOobResources(performanceController);
clock.tick(1);

// Force the page load event to be sent
stub(mockWindow.document, 'visibilityState').value('hidden');
callEventListener('visibilitychange');

expect(api.onFirstInputDelay).to.be.called;
expect(createOobTraceStub).not.to.be.called;
clock.tick(5000);
expect(createOobTraceStub).to.be.calledWithExactly(
performanceController,
[NAVIGATION_PERFORMANCE_ENTRY],
[PAINT_PERFORMANCE_ENTRY],
{},
undefined
);
});

it('logs first input delay if polyfill is available and callback is called', () => {
getIidStub.returns(MOCK_ID);
const api = Api.getInstance();
Expand Down
30 changes: 7 additions & 23 deletions packages/performance/src/services/oob_resources_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import { WebVitalMetrics } from '../resources/web_vitals';
import { Api } from './api_service';
import { getIid } from './iid_service';

const FID_WAIT_TIME_MS = 5000;

let webVitalMetrics: WebVitalMetrics = {};
let sentPageLoadTrace: boolean = false;
let firstInputDelay: number | undefined;
Expand Down Expand Up @@ -147,27 +145,13 @@ function sendOobTrace(performanceController: PerformanceController): void {
'navigation'
) as PerformanceNavigationTiming[];
const paintTimings = api.getEntriesByType('paint');
// If First Input Delay polyfill is added to the page, report the fid value.
// https://github.com/GoogleChromeLabs/first-input-delay
if (api.onFirstInputDelay && !firstInputDelay) {
setTimeout(() => {
Trace.createOobTrace(
performanceController,
navigationTimings,
paintTimings,
webVitalMetrics,
firstInputDelay
);
}, FID_WAIT_TIME_MS);
} else {
Trace.createOobTrace(
performanceController,
navigationTimings,
paintTimings,
webVitalMetrics,
firstInputDelay
);
}
Trace.createOobTrace(
performanceController,
navigationTimings,
paintTimings,
webVitalMetrics,
firstInputDelay
);
}
}

Expand Down

0 comments on commit 4b4d9ad

Please sign in to comment.