Skip to content

Commit

Permalink
Only do selector lookup on attribution
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed May 10, 2024
1 parent c3464c2 commit d36a31e
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/attribution/onINP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const entryToRenderTimeMap: WeakMap<
> = new WeakMap();

// A mapping of interactions to the target selector
export const interactionTargetMap: Map<number, string> = new Map();
export const interactionTargetMap: Map<number, Node> = new Map();

// A reference to the idle task used to clean up entries from the above
// variables. If the value is -1 it means no task is queue, and if it's
Expand All @@ -85,14 +85,9 @@ const saveInteractionSelector = (entry: PerformanceEventTiming) => {
const interactionId = entry.interactionId;
if (!interactionId) return;

// Don't run the getSelector for keyboard events as there could be a lot of
// them in short fashion when typing. Allow first-input as only one of them.
if (entry.entryType !== 'first-input' && entry.name.startsWith('key')) return;

// Save any new selectors
if (!interactionTargetMap.get(interactionId) && entry.target) {
const selector = getSelector(entry.target);
if (selector) interactionTargetMap.set(interactionId, selector);
interactionTargetMap.set(interactionId, entry.target);
}
};

Expand Down Expand Up @@ -243,7 +238,7 @@ const attributeINP = (metric: INPMetric): INPMetricWithAttribution => {
const firstEntryWithTarget = metric.entries.find((entry) => entry.target);
const interactionTarget = firstEntryWithTarget
? getSelector(firstEntryWithTarget.target)
: interactionTargetMap.get(firstEntry.interactionId) || '';
: getSelector(interactionTargetMap.get(firstEntry.interactionId)) || '';

// Since entry durations are rounded to the nearest 8ms, we need to clamp
// the `nextPaintTime` value to be higher than the `processingEnd` or
Expand Down

0 comments on commit d36a31e

Please sign in to comment.