New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 228: Change onINP to also use FID duration
when under durationTheshold
#231
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,19 +30,21 @@ interface PerformanceEntriesHandler { | |
* try/catch to avoid errors in unsupporting browsers. | ||
*/ | ||
export const observe = ( | ||
type: string, | ||
types: string[], | ||
callback: PerformanceEntriesHandler, | ||
opts?: PerformanceObserverInit, | ||
): PerformanceObserver | undefined => { | ||
try { | ||
if (PerformanceObserver.supportedEntryTypes.includes(type)) { | ||
if (types.every(type => PerformanceObserver.supportedEntryTypes.includes(type))) { | ||
const po: PerformanceObserver = new PerformanceObserver((list) => { | ||
callback(list.getEntries()); | ||
}); | ||
po.observe(Object.assign({ | ||
type, | ||
buffered: true, | ||
}, opts || {}) as PerformanceObserverInit); | ||
for (let type of types) { | ||
po.observe(Object.assign({ | ||
type, | ||
buffered: true, | ||
}, opts || {}) as PerformanceObserverInit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, the same options are passed for all registered types. This is fine for this specific case. But in general we may want to have |
||
} | ||
return po; | ||
} | ||
} catch (e) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,7 @@ export const onINP = (onReport: ReportCallback, opts?: ReportOpts) => { | |
|
||
const handleEntries = (entries: Metric['entries']) => { | ||
(entries as PerformanceEventTiming[]).forEach((entry) => { | ||
if (entry.interactionId) { | ||
if (entry.entryType == 'first-input' || entry.interactionId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only needed until For now, this leads to the "10 worst" list being 1 larger. But since web-vitals.js doesn't use that to count number of interactions, it doesn't really matter. The only time it matters is if the |
||
processEntry(entry); | ||
} | ||
}); | ||
|
@@ -130,7 +130,7 @@ export const onINP = (onReport: ReportCallback, opts?: ReportOpts) => { | |
} | ||
}; | ||
|
||
const po = observe('event', handleEntries, { | ||
const po = observe(['first-input', 'event'], handleEntries, { | ||
// Event Timing entries have their durations rounded to the nearest 8ms, | ||
// so a duration of 40ms would be any event that spans 2.5 or more frames | ||
// at 60Hz. This threshold is chosen to strike a balance between usefulness | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered making this
string || string[]
and adjusting this implementation to support either option... decided it was better to make a single choice but totally understand alterantive.