Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

mmocny
Copy link
Member

@mmocny mmocny commented May 24, 2022

This is a PROTOTYPE for adding support for registering multiple observer types with the same PO observer -- specifically to use both first-input and event timing together, with the same PerformanceObserver / handler.

I have not tested this thoroughly, just checking to see how it would look for now and to continue conversation.

Context:

@@ -30,19 +30,21 @@ interface PerformanceEntriesHandler {
* try/catch to avoid errors in unsupporting browsers.
*/
export const observe = (
type: string,
types: string[],
Copy link
Member Author

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.

po.observe(Object.assign({
type,
buffered: true,
}, opts || {}) as PerformanceObserverInit);
Copy link
Member Author

Choose a reason for hiding this comment

The 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 [string, PerformanceObserverInit][] (aka array of tuple) instead

@@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only needed until first-input gets a proper interactionID.

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 first-input duration becomes the 10th largest and ends up evicting another interaction from the list, and then you also have 500 interactions.

@philipwalton
Copy link
Member

Thanks for filing @mmocny. This PR helped me realize that the change to support #228 wouldn't end up being much extra code.

I did have some concerns about this implementation, though, so I filed #232 to compare. One issue I encountered with this PR is that some of the tests fail (specifically the ones that test the high-percentile logic) because they create a long first interaction and then assert that that interaction is not INP after 50 additional interactions. But if we don't dedupe cases where the first-input entry is also one of the longest interactions, then that logic breaks. In reality I don't think it would be a huge deal, but it was easy enough for me to dedupe those, and then I didn't have to change the test logic.

I also thought it would be easier to do a one-off additional observe() call in onINP() rather than adding support for additional types in the helper module.

LMKWYT.

@mmocny
Copy link
Member Author

mmocny commented May 30, 2022

Yes I figured those types of tests would break, but decided it wasn't likely a big deal on real sites (i.e. the difference wouldn't come up in p75 field data).

However, if you found a way to dedupe, woot! I'll take a look at that patch.

@mmocny mmocny closed this May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants