Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Mar 19, 2024
1 parent 2b6ff70 commit 4372eb2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/attribution/onFCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {getBFCacheRestoreTime} from '../lib/bfcache.js';
import {getLoadState} from '../lib/getLoadState.js';
import {getNavigationEntry} from '../lib/getNavigationEntry.js';
import {invalidTiming} from '../lib/invalidTiming.js';
import {isInvalidTimestamp} from '../lib/isInvalidTimestamp.js';
import {onFCP as unattributedOnFCP} from '../onFCP.js';
import {
FCPMetric,
Expand All @@ -34,7 +34,7 @@ const attributeFCP = (metric: FCPMetric): void => {

if (navigationEntry) {
const responseStart = navigationEntry.responseStart;
if (invalidTiming(responseStart)) return;
if (isInvalidTimestamp(responseStart)) return;

const activationStart = navigationEntry.activationStart || 0;
const ttfb = Math.max(0, responseStart - activationStart);
Expand Down
4 changes: 2 additions & 2 deletions src/attribution/onLCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {getNavigationEntry} from '../lib/getNavigationEntry.js';
import {getSelector} from '../lib/getSelector.js';
import {invalidTiming} from '../lib/invalidTiming.js';
import {isInvalidTimestamp} from '../lib/isInvalidTimestamp.js';
import {onLCP as unattributedOnLCP} from '../onLCP.js';
import {
LCPAttribution,
Expand All @@ -33,7 +33,7 @@ const attributeLCP = (metric: LCPMetric) => {

if (navigationEntry) {
const responseStart = navigationEntry.responseStart;
if (invalidTiming(responseStart)) return;
if (isInvalidTimestamp(responseStart)) return;

const activationStart = navigationEntry.activationStart || 0;
const lcpEntry = metric.entries[metric.entries.length - 1];
Expand Down
4 changes: 2 additions & 2 deletions src/lib/invalidTiming.ts → src/lib/isInvalidTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

export const invalidTiming = (timing: number) => {
export const isInvalidTimestamp = (timestamp: DOMHighResTimeStamp) => {
// In some cases no value is reported by the browser (for
// privacy/security reasons), and in other cases (bugs) the value is
// negative or is larger than the current page time. Ignore these cases:
// https://github.com/GoogleChrome/web-vitals/issues/137
// https://github.com/GoogleChrome/web-vitals/issues/162
// https://github.com/GoogleChrome/web-vitals/issues/275
return timing <= 0 || timing > performance.now();
return timestamp <= 0 || timestamp > performance.now();
};
4 changes: 2 additions & 2 deletions src/onTTFB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {bindReporter} from './lib/bindReporter.js';
import {initMetric} from './lib/initMetric.js';
import {invalidTiming} from './lib/invalidTiming.js';
import {isInvalidTimestamp} from './lib/isInvalidTimestamp.js';
import {onBFCacheRestore} from './lib/bfcache.js';
import {getNavigationEntry} from './lib/getNavigationEntry.js';
import {
Expand Down Expand Up @@ -78,7 +78,7 @@ export const onTTFB = (onReport: TTFBReportCallback, opts?: ReportOpts) => {
if (navEntry) {
const responseStart = navEntry.responseStart;

if (invalidTiming(responseStart)) return;
if (isInvalidTimestamp(responseStart)) return;

// The activationStart reference is used because TTFB should be
// relative to page activation rather than navigation start if the
Expand Down

0 comments on commit 4372eb2

Please sign in to comment.