Skip to content

Commit 8ee8e56

Browse files
committed
feat: upgrade web-vitals to 4.x
1 parent dad0a28 commit 8ee8e56

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"shimmer": "^1.2.1",
126126
"ua-parser-js": "^1.0.33",
127127
"uuid": "^9.0.0",
128-
"web-vitals": "^3.0.2"
128+
"web-vitals": "^4.0.0"
129129
},
130130
"lint-staged": {
131131
"*.ts": "npm run lint:errors",

src/plugins/event-plugins/WebVitalsPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class WebVitalsPlugin extends InternalPlugin {
8383
url: a.url,
8484
timeToFirstByte: a.timeToFirstByte,
8585
resourceLoadDelay: a.resourceLoadDelay,
86-
resourceLoadTime: a.resourceLoadTime,
86+
resourceLoadTime: a.resourceLoadDuration,
8787
elementRenderDelay: a.elementRenderDelay
8888
};
8989
if (a.lcpResourceEntry) {

src/plugins/event-plugins/__tests__/WebVitalsPlugin.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import { context, record } from '../../../test-utils/test-utils';
1818
import { Topic } from '../../../event-bus/EventBus';
1919
import { WebVitalsPlugin } from '../WebVitalsPlugin';
2020
import { navigationEvent } from '../../../test-utils/mock-data';
21+
import {
22+
CLSMetricWithAttribution,
23+
FIDMetricWithAttribution,
24+
LCPMetricWithAttribution
25+
} from 'web-vitals';
2126

2227
const mockLCPData = {
2328
delta: 239.51,
@@ -29,10 +34,10 @@ const mockLCPData = {
2934
url: 'example.com/source.png',
3035
timeToFirstByte: 1000,
3136
resourceLoadDelay: 250,
32-
resourceLoadTime: 1000,
37+
resourceLoadDuration: 1000,
3338
elementRenderDelay: 250
3439
}
35-
};
40+
} as LCPMetricWithAttribution;
3641

3742
const mockFIDData = {
3843
delta: 1.2799999676644802,
@@ -45,7 +50,7 @@ const mockFIDData = {
4550
eventType: 'keydown',
4651
loadState: 'dom-interactive'
4752
}
48-
};
53+
} as FIDMetricWithAttribution;
4954

5055
const mockCLSData = {
5156
delta: 0,
@@ -58,7 +63,7 @@ const mockCLSData = {
5863
largestShiftTime: 3447485.600000024,
5964
loadState: 'dom-interactive'
6065
}
61-
};
66+
} as CLSMetricWithAttribution;
6267

6368
// only need hasLatency fields
6469
const imagePerformanceEntry = {
@@ -128,7 +133,8 @@ describe('WebVitalsPlugin tests', () => {
128133
timeToFirstByte: mockLCPData.attribution.timeToFirstByte,
129134
resourceLoadDelay:
130135
mockLCPData.attribution.resourceLoadDelay,
131-
resourceLoadTime: mockLCPData.attribution.resourceLoadTime,
136+
resourceLoadTime:
137+
mockLCPData.attribution.resourceLoadDuration,
132138
elementRenderDelay:
133139
mockLCPData.attribution.elementRenderDelay
134140
})

0 commit comments

Comments
 (0)