Skip to content

Commit 6c383c4

Browse files
committed
feat: update types
1 parent 019cf99 commit 6c383c4

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

packages/browser-utils/src/metrics/web-vitals/types.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ interface PerformanceEntryMap {
3030
navigation: PerformanceNavigationTiming;
3131
resource: PerformanceResourceTiming;
3232
paint: PerformancePaintTiming;
33+
'interaction-contentful-paint': InteractionContentfulPaint;
34+
'soft-navigation': SoftNavigationEntry;
3335
}
3436

3537
// Update built-in types to be more accurate.
@@ -45,27 +47,36 @@ declare global {
4547
getEntriesByType<K extends keyof PerformanceEntryMap>(type: K): PerformanceEntryMap[K][];
4648
}
4749

50+
// https://w3c.github.io/event-timing/#sec-modifications-perf-timeline
51+
interface PerformancePaintTiming extends PerformanceEntry {
52+
navigationId?: string;
53+
}
54+
4855
// https://w3c.github.io/event-timing/#sec-modifications-perf-timeline
4956
interface PerformanceObserverInit {
5057
durationThreshold?: number;
58+
includeSoftNavigationObservations?: boolean;
5159
}
5260

5361
// https://wicg.github.io/nav-speculation/prerendering.html#performance-navigation-timing-extension
5462
interface PerformanceNavigationTiming {
5563
activationStart?: number;
64+
navigationId?: string;
5665
}
5766

5867
// https://wicg.github.io/event-timing/#sec-performance-event-timing
5968
interface PerformanceEventTiming extends PerformanceEntry {
6069
duration: DOMHighResTimeStamp;
6170
interactionId: number;
71+
navigationId?: string;
6272
}
6373

6474
// https://wicg.github.io/layout-instability/#sec-layout-shift-attribution
6575
interface LayoutShiftAttribution {
6676
node: Node | null;
6777
previousRect: DOMRectReadOnly;
6878
currentRect: DOMRectReadOnly;
79+
navigationId?: string;
6980
}
7081

7182
// https://wicg.github.io/layout-instability/#sec-layout-shift
@@ -83,6 +94,22 @@ declare global {
8394
readonly id: string;
8495
readonly url: string;
8596
readonly element: Element | null;
97+
navigationId?: string;
98+
}
99+
100+
// https://github.com/WICG/soft-navigations
101+
interface SoftNavigationEntry extends PerformanceEntry {
102+
navigationId?: string;
103+
}
104+
105+
interface InteractionContentfulPaint extends PerformanceEntry {
106+
readonly renderTime: DOMHighResTimeStamp;
107+
readonly loadTime: DOMHighResTimeStamp;
108+
readonly size: number;
109+
readonly id: string;
110+
readonly url: string;
111+
readonly element: Element | null;
112+
navigationId?: string;
86113
}
87114

88115
// https://w3c.github.io/long-animation-frame/#sec-PerformanceLongAnimationFrameTiming

packages/browser-utils/src/metrics/web-vitals/types/base.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,30 @@ export interface Metric {
7272
* - 'prerender': for pages that were prerendered.
7373
* - 'restore': for pages that were discarded by the browser and then
7474
* restored by the user.
75+
* - 'soft-navigation': for soft navigations.
7576
*/
76-
navigationType: 'navigate' | 'reload' | 'back-forward' | 'back-forward-cache' | 'prerender' | 'restore';
77+
navigationType:
78+
| 'navigate'
79+
| 'reload'
80+
| 'back-forward'
81+
| 'back-forward-cache'
82+
| 'prerender'
83+
| 'restore'
84+
| 'soft-navigation';
85+
86+
/**
87+
* The navigationId the metric happened for. This is particularly relevant for soft navigations where
88+
* the metric may be reported for a previous URL.
89+
*
90+
* navigationIds are UUID strings.
91+
*/
92+
navigationId: string;
93+
94+
/**
95+
* The navigation URL the metric happened for. This is particularly relevant for soft navigations where
96+
* the metric may be reported for a previous URL.
97+
*/
98+
navigationURL?: string;
7799
}
78100

79101
/** The union of supported metric types. */
@@ -113,6 +135,8 @@ export interface ReportCallback {
113135

114136
export interface ReportOpts {
115137
reportAllChanges?: boolean;
138+
durationThreshold?: number;
139+
reportSoftNavs?: boolean;
116140
}
117141

118142
export interface AttributionReportOpts extends ReportOpts {

packages/browser-utils/src/metrics/web-vitals/types/fcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export interface FCPAttribution {
5252
/**
5353
* The `navigation` entry of the current page, which is useful for diagnosing
5454
* general page load issues. This can be used to access `serverTiming` for example:
55-
* navigationEntry?.serverTiming
55+
* navigationEntry.serverTiming
5656
*/
57-
navigationEntry?: PerformanceNavigationTiming;
57+
navigationEntry?: PerformanceNavigationTiming | SoftNavigationEntry;
5858
}
5959

6060
/**

packages/browser-utils/src/metrics/web-vitals/types/lcp.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { Metric } from './base.js';
2121
*/
2222
export interface LCPMetric extends Metric {
2323
name: 'LCP';
24-
entries: LargestContentfulPaint[];
24+
entries: (LargestContentfulPaint | InteractionContentfulPaint)[];
2525
}
2626

2727
/**
@@ -70,18 +70,19 @@ export interface LCPAttribution {
7070
/**
7171
* The `navigation` entry of the current page, which is useful for diagnosing
7272
* general page load issues. This can be used to access `serverTiming` for example:
73-
* navigationEntry?.serverTiming
73+
* navigationEntry.serverTiming
7474
*/
75-
navigationEntry?: PerformanceNavigationTiming;
75+
navigationEntry?: PerformanceNavigationTiming | SoftNavigationEntry;
7676
/**
7777
* The `resource` entry for the LCP resource (if applicable), which is useful
7878
* for diagnosing resource load issues.
7979
*/
8080
lcpResourceEntry?: PerformanceResourceTiming;
8181
/**
82-
* The `LargestContentfulPaint` entry corresponding to LCP.
82+
* The `LargestContentfulPaint` entry corresponding to LCP
83+
* (or `InteractionContentfulPaint` for soft navigations).
8384
*/
84-
lcpEntry?: LargestContentfulPaint;
85+
lcpEntry?: LargestContentfulPaint | InteractionContentfulPaint;
8586
}
8687

8788
/**

packages/browser-utils/src/metrics/web-vitals/types/ttfb.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { Metric } from './base';
2121
*/
2222
export interface TTFBMetric extends Metric {
2323
name: 'TTFB';
24-
entries: PerformanceNavigationTiming[];
24+
entries: PerformanceNavigationTiming[] | SoftNavigationEntry[];
2525
}
2626

2727
/**
@@ -65,9 +65,9 @@ export interface TTFBAttribution {
6565
/**
6666
* The `navigation` entry of the current page, which is useful for diagnosing
6767
* general page load issues. This can be used to access `serverTiming` for
68-
* example: navigationEntry?.serverTiming
68+
* example: navigationEntry.serverTiming
6969
*/
70-
navigationEntry?: PerformanceNavigationTiming;
70+
navigationEntry?: PerformanceNavigationTiming | SoftNavigationEntry;
7171
}
7272

7373
/**

0 commit comments

Comments
 (0)