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

Update onINP to also observe first-input entries #232

Merged
merged 1 commit into from May 30, 2022
Merged

Conversation

philipwalton
Copy link
Member

Fixes #228 by having the observer created in onINP() also observe first-input entries (in addition to event)—given that they are both instances of PerformanceEventTiming.

This PR also includes logic to remove duplicate interactions by checking to see if a first-input and event entry both have the same startTime and duration values. This logic is needed until crbug/1325826 is fixed in Chrome, which adds support for the interactionId property on first-input entries.

/cc @mmocny

Copy link
Member

@mmocny mmocny left a comment

Choose a reason for hiding this comment

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

I don't think this is perfect either, but I think its a good change and cleaner than the one I suggested.

Cheers!

// Note that this logic assumes that `event` entries are dispatched
// before `first-input` entries. This is true in Chrome but it is not
// true in Firefox; however, Firefox doesn't support interactionId, so
// it's not an issue at the moment.
Copy link
Member

Choose a reason for hiding this comment

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

I was surprised to learn this, since I think we fire FID first.

However, I guess you mean that the order of Entries in the PO callbacks, when there are multiple observe() calls of different types... This I haven't tested and I'm not sure if order is guaranteed or arbitrary right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I only tested this in Chrome on Mac (desktop), but no matter what I did, which order I called observe() in, or which event I used, I always got the event entry processed before the first-input entry.

});
});
if (noMatchingEntry) {
processEntry(entry);
Copy link
Member

Choose a reason for hiding this comment

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

What happens if:

  • FID is pointerdown, but we do not get a pointerdown event timing entry
  • Then we do get an pointerup event timing entry (for the same interaction)

I think it will be treated as 2 different interactions here, also affecting p98.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think so. My hope is we can remove this logic entirely once first-input entries have an interactionId property. My goal here was to minimize these types of occurrences .

@@ -143,6 +163,10 @@ export const onINP = (onReport: ReportCallback, opts?: ReportOpts) => {
report = bindReporter(onReport, metric, opts.reportAllChanges);

if (po) {
// Also observe entries of type `first-input`. This is useful in cases
// where the first interaction is less than the `durationThreshold`.
po.observe({type: 'first-input', buffered: true});
Copy link
Member

Choose a reason for hiding this comment

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

Yeah this seems better :)

@@ -89,7 +89,7 @@
inp.entries = inp.entries.map((e) => ({
...e.toJSON(),
interactionId: e.interactionId,
target: e.target.nodeName.toLowerCase(),
target: e.target?.nodeName.toLowerCase(),
Copy link
Member

Choose a reason for hiding this comment

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

Is this related to FID entry?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, not sure why but I started noticing lots of cases where target was undefined on first-input entries. I didn't look much further into repo-ing why.

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.

None yet

2 participants