Skip to content

Commit 398e207

Browse files
committed
🐛 notify deferred resource events synchronously after delay
The deferred setTimeout path used handleResource which routes through the task queue's requestIdleCallback. That callback can fire after the click action's PAGE_ACTIVITY_END_DELAY window closes, leaving the resource uncounted by its parent action. Notify the lifecycle synchronously once the matching delay elapses so the resource is attributed correctly.
1 parent 14c42eb commit 398e207

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

packages/rum-core/src/domain/resource/resourceCollection.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,19 @@ export function startResourceCollection(lifeCycle: LifeCycle, configuration: Rum
6262
// (notably on Firefox), so the matching REQUEST_COMPLETED isn't in the registry yet.
6363
// Defer the lookup to give the request time to land before we look it up.
6464
//
65+
// Publish synchronously after the delay rather than via the task queue: the queue's
66+
// requestIdleCallback can fire after the click action's PAGE_ACTIVITY_END_DELAY window
67+
// (notably on newer Chromium scheduling), leaving the request uncounted by its parent
68+
// action.
69+
//
6570
// Note: we could clear the timeout on stop(), but this requires a bit of bookkeeping that
6671
// is not necessary right now. We could reevaluate in the future.
67-
setTimeout(
68-
() => handleResource(() => assembleResource(entry, requestRegistry.getMatchingRequest(entry), configuration)),
69-
REQUEST_MATCHING_DELAY
70-
)
72+
setTimeout(() => {
73+
const rawEvent = assembleResource(entry, requestRegistry.getMatchingRequest(entry), configuration)
74+
if (rawEvent) {
75+
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)
76+
}
77+
}, REQUEST_MATCHING_DELAY)
7178
} else {
7279
handleResource(() => assembleResource(entry, undefined, configuration))
7380
}

0 commit comments

Comments
 (0)