Skip to content

Commit

Permalink
🐛 fix loadEvent v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Nov 23, 2020
1 parent a26a590 commit 762f223
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('trackTimings', () => {
domContentLoaded: 345,
domInteractive: 234,
firstContentfulPaint: 123,
loadEventEnd: 567,
loadEvent: 567,
})
})
})
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('trackNavigationTimings', () => {
domComplete: 456,
domContentLoaded: 345,
domInteractive: 234,
loadEventEnd: 567,
loadEvent: 567,
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Timings {
domInteractive?: number
domContentLoaded?: number
domComplete?: number
loadEventEnd?: number
loadEvent?: number
largestContentfulPaint?: number
}

Expand Down Expand Up @@ -44,7 +44,7 @@ export function trackNavigationTimings(lifeCycle: LifeCycle, callback: (newTimin
domComplete: entry.domComplete,
domContentLoaded: entry.domContentLoadedEventEnd,
domInteractive: entry.domInteractive,
loadEventEnd: entry.loadEventEnd,
loadEvent: entry.loadEventEnd,
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ describe('rum view measures', () => {
domComplete: 456,
domContentLoaded: 345,
domInteractive: 234,
loadEventEnd: 567,
loadEvent: 567,
})
})

Expand All @@ -511,7 +511,7 @@ describe('rum view measures', () => {
domInteractive: 234,
firstContentfulPaint: 123,
largestContentfulPaint: 789,
loadEventEnd: 567,
loadEvent: 567,
})
expect(getViewEvent(2).timings).toEqual({})
})
Expand Down Expand Up @@ -563,7 +563,7 @@ describe('rum view measures', () => {
domInteractive: 234,
firstContentfulPaint: 123,
largestContentfulPaint: 789,
loadEventEnd: 567,
loadEvent: 567,
})
})

Expand Down
18 changes: 9 additions & 9 deletions packages/rum/src/domain/rumEventsCollection/view/trackViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function newView(
scheduleViewUpdate()
})

const { setActivityLoadingTime, setLoadEventEnd } = trackLoadingTime(loadingType, (newLoadingTime) => {
const { setActivityLoadingTime, setLoadEvent } = trackLoadingTime(loadingType, (newLoadingTime) => {
loadingTime = newLoadingTime
scheduleViewUpdate()
})
Expand Down Expand Up @@ -171,8 +171,8 @@ function newView(
},
updateTimings(newTimings: Timings) {
timings = newTimings
if (newTimings.loadEventEnd !== undefined) {
setLoadEventEnd(newTimings.loadEventEnd)
if (newTimings.loadEvent !== undefined) {
setLoadEvent(newTimings.loadEvent)
}
},
updateLocation(newLocation: Location) {
Expand Down Expand Up @@ -208,21 +208,21 @@ function trackHash(onHashChange: () => void) {
}

function trackLoadingTime(loadType: ViewLoadingType, callback: (loadingTime: number) => void) {
let isWaitingForLoadEventEnd = loadType === ViewLoadingType.INITIAL_LOAD
let isWaitingForLoadEvent = loadType === ViewLoadingType.INITIAL_LOAD
let isWaitingForActivityLoadingTime = true
const loadingTimeCandidates: number[] = []

function invokeCallbackIfAllCandidatesAreReceived() {
if (!isWaitingForActivityLoadingTime && !isWaitingForLoadEventEnd && loadingTimeCandidates.length > 0) {
if (!isWaitingForActivityLoadingTime && !isWaitingForLoadEvent && loadingTimeCandidates.length > 0) {
callback(Math.max(...loadingTimeCandidates))
}
}

return {
setLoadEventEnd(loadEventEnd: number) {
if (isWaitingForLoadEventEnd) {
isWaitingForLoadEventEnd = false
loadingTimeCandidates.push(loadEventEnd)
setLoadEvent(loadEvent: number) {
if (isWaitingForLoadEvent) {
isWaitingForLoadEvent = false
loadingTimeCandidates.push(loadEvent)
invokeCallbackIfAllCandidatesAreReceived()
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('viewCollection', () => {
domInteractive: 10,
firstContentfulPaint: 10,
largestContentfulPaint: 10,
loadEventEnd: 10,
loadEvent: 10,
},
}
lifeCycle.notify(LifeCycleEventType.VIEW_UPDATED, view as View)
Expand All @@ -68,7 +68,7 @@ describe('viewCollection', () => {
},
firstContentfulPaint: 10 * 1e6,
largestContentfulPaint: 10 * 1e6,
loadEventEnd: 10 * 1e6,
loadEvent: 10 * 1e6,
loadingTime: 20 * 1e6,
loadingType: ViewLoadingType.INITIAL_LOAD,
longTask: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function processViewUpdate(view: View) {
},
firstContentfulPaint: msToNs(view.timings.firstContentfulPaint),
largestContentfulPaint: msToNs(view.timings.largestContentfulPaint),
loadEventEnd: msToNs(view.timings.loadEventEnd),
loadEvent: msToNs(view.timings.loadEvent),
loadingTime: msToNs(view.loadingTime),
loadingType: view.loadingType,
longTask: {
Expand Down
9 changes: 2 additions & 7 deletions packages/rum/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface RumViewEvent {
domInteractive?: number
domContentLoaded?: number
domComplete?: number
loadEventEnd?: number
loadEvent?: number
loadingTime?: number
timeSpent: number
error: Count
Expand Down Expand Up @@ -102,12 +102,7 @@ export interface RumActionEvent {
}
}

export type RawRumEvent =
| RumErrorEvent
| RumResourceEvent
| RumViewEvent
| RumLongTaskEvent
| RumActionEvent
export type RawRumEvent = RumErrorEvent | RumResourceEvent | RumViewEvent | RumLongTaskEvent | RumActionEvent

export interface RumContext {
date: number
Expand Down

0 comments on commit 762f223

Please sign in to comment.