File tree Expand file tree Collapse file tree 5 files changed +9
-9
lines changed
packages/browser-utils/src/metrics/web-vitals/lib Expand file tree Collapse file tree 5 files changed +9
-9
lines changed Original file line number Diff line number Diff 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
3030const 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
6262export 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
Original file line number Diff line number Diff 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' ] ;
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 1717import { WINDOW } from '../../../types' ;
1818
1919export 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 }
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments