Skip to content

Commit d7eff9a

Browse files
committed
remove optional chains
1 parent 4c971f3 commit d7eff9a

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

packages/browser-utils/src/metrics/web-vitals/lib/getVisibilityWatcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const initHiddenTime = () => {
2424
// that visibility state is always 'hidden' during prerendering, so we have
2525
// to ignore that case until prerendering finishes (see: `prerenderingchange`
2626
// event logic below).
27-
return WINDOW.document?.visibilityState === 'hidden' && !WINDOW.document?.prerendering ? 0 : Infinity;
27+
return WINDOW.document!.visibilityState === 'hidden' && !WINDOW.document!.prerendering ? 0 : Infinity;
2828
};
2929

3030
const onVisibilityUpdate = (event: Event) => {
3131
// If the document is 'hidden' and no previous hidden timestamp has been
3232
// set, update it based on the current event data.
33-
if (WINDOW.document?.visibilityState === 'hidden' && firstHiddenTime > -1) {
33+
if (WINDOW.document!.visibilityState === 'hidden' && firstHiddenTime > -1) {
3434
// If the event is a 'visibilitychange' event, it means the page was
3535
// visible prior to this change, so the event timestamp is the first
3636
// hidden time.
@@ -60,7 +60,7 @@ const removeChangeListeners = () => {
6060
};
6161

6262
export const getVisibilityWatcher = () => {
63-
if (firstHiddenTime < 0) {
63+
if (WINDOW.document && firstHiddenTime < 0) {
6464
// If the document is hidden when this code runs, assume it was hidden
6565
// since navigation start. This isn't a perfect heuristic, but it's the
6666
// best we can do until an API is available to support querying past

packages/browser-utils/src/metrics/web-vitals/lib/initMetric.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export const initMetric = <MetricName extends MetricType['name']>(name: MetricNa
2525
let navigationType: MetricType['navigationType'] = 'navigate';
2626

2727
if (navEntry) {
28-
if (WINDOW.document?.prerendering || getActivationStart() > 0) {
28+
if ((WINDOW.document && WINDOW.document.prerendering) || getActivationStart() > 0) {
2929
navigationType = 'prerender';
30-
} else if (WINDOW.document?.wasDiscarded) {
30+
} else if (WINDOW.document && WINDOW.document.wasDiscarded) {
3131
navigationType = 'restore';
3232
} else if (navEntry.type) {
3333
navigationType = navEntry.type.replace(/_/g, '-') as MetricType['navigationType'];

packages/browser-utils/src/metrics/web-vitals/lib/interactions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const processInteractionEntry = (entry: PerformanceEventTiming) => {
113113
existingInteraction.latency = entry.duration;
114114
} else if (
115115
entry.duration === existingInteraction.latency &&
116-
entry.startTime === existingInteraction?.entries[0]?.startTime
116+
entry.startTime === (existingInteraction.entries[0] && existingInteraction.entries[0].startTime)
117117
) {
118118
existingInteraction.entries.push(entry);
119119
}

packages/browser-utils/src/metrics/web-vitals/lib/whenActivated.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import { WINDOW } from '../../../types';
1818

1919
export const whenActivated = (callback: () => void) => {
20-
if (WINDOW.document?.prerendering) {
21-
WINDOW.document?.addEventListener('prerenderingchange', () => callback(), true);
20+
if (WINDOW.document && WINDOW.document.prerendering) {
21+
addEventListener('prerenderingchange', () => callback(), true);
2222
} else {
2323
callback();
2424
}

packages/browser-utils/src/metrics/web-vitals/lib/whenIdle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const whenIdle = (cb: () => void): number => {
3030
cb = runOnce(cb) as () => void;
3131
// If the document is hidden, run the callback immediately, otherwise
3232
// race an idle callback with the next `visibilitychange` event.
33-
if (WINDOW.document?.visibilityState === 'hidden') {
33+
if (WINDOW.document && WINDOW.document.visibilityState === 'hidden') {
3434
cb();
3535
} else {
3636
handle = rIC(cb);

0 commit comments

Comments
 (0)