GoogleChrome / web-vitals

Essential metrics for a healthy site.
https://web.dev/vitals
Apache License 2.0
7.49k stars 410 forks source link

Pick the first non-null target for INP attribution #421

Closed rviscomi closed 7 months ago

rviscomi commented 7 months ago

Some pointer entries have a known bug causing them to have null event targets. In cases where there are mouse or click entries in the same interaction that do have non-null event targets, always prefer those.

This PR works around the bug by changing the eventTarget in INP attribution to use the first entry in the list having a non-null target, rather than always using the longest entry in the list, which may sometimes be a pointer entry.

tunetheweb commented 7 months ago

@mmocny can you review?

mmocny commented 7 months ago

This PR is similar to the strategy I've been advertising for measuring interaction targets.

--

There is also a different strategy that works around the other problem with event targets... that they can be removed and GC-ed by the time Event Timing is reported.

That gist is very rough, but gives you the idea: manage a map of event type + timestamp to whatever metadata you want, saved during event dispatch, then look it up from Event Timing.

philipwalton commented 7 months ago

I added a test to cover the logic Rick added. It fails when run against main but passed when run on this branch.