Skip to content

Commit 532c68b

Browse files
committed
ref: Don't use BFCache
1 parent d352627 commit 532c68b

File tree

9 files changed

+7
-374
lines changed

9 files changed

+7
-374
lines changed

packages/tracing/src/browser/web-vitals/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ Current vendored web vitals are:
1616

1717
[Apache 2.0](https://github.com/GoogleChrome/web-vitals/blob/master/LICENSE)
1818

19-
## Notable differences from `web-vitals` library
20-
21-
TODO(abhi): Fill this out
22-
2319
## CHANGELOG
2420

2521
https://github.com/getsentry/sentry-javascript/pull/3515

packages/tracing/src/browser/web-vitals/getCLS.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { getFCP } from './getFCP';
1817
import { bindReporter } from './lib/bindReporter';
1918
import { initMetric } from './lib/initMetric';
2019
import { observe, PerformanceEntryHandler } from './lib/observe';
21-
import { onBFCacheRestore } from './lib/onBFCacheRestore';
2220
import { onHidden } from './lib/onHidden';
2321
import { ReportHandler } from './types';
2422

@@ -36,26 +34,8 @@ export interface LayoutShiftAttribution {
3634
currentRect: DOMRectReadOnly;
3735
}
3836

39-
let isMonitoringFCP = false;
40-
let fcpValue = -1;
41-
4237
export const getCLS = (onReport: ReportHandler, reportAllChanges?: boolean): void => {
43-
// Start monitoring FCP so we can only report CLS if FCP is also reported.
44-
// Note: this is done to match the current behavior of CrUX.
45-
if (!isMonitoringFCP) {
46-
getFCP(metric => {
47-
fcpValue = metric.value;
48-
});
49-
isMonitoringFCP = true;
50-
}
51-
52-
const onReportWrapped: ReportHandler = arg => {
53-
if (fcpValue > -1) {
54-
onReport(arg);
55-
}
56-
};
57-
58-
let metric = initMetric('CLS', 0);
38+
const metric = initMetric('CLS', 0);
5939
let report: ReturnType<typeof bindReporter>;
6040

6141
let sessionValue = 0;
@@ -94,18 +74,11 @@ export const getCLS = (onReport: ReportHandler, reportAllChanges?: boolean): voi
9474

9575
const po = observe('layout-shift', entryHandler as PerformanceEntryHandler);
9676
if (po) {
97-
report = bindReporter(onReportWrapped, metric, reportAllChanges);
77+
report = bindReporter(onReport, metric, reportAllChanges);
9878

9979
onHidden(() => {
10080
po.takeRecords().map(entryHandler as PerformanceEntryHandler);
10181
report(true);
10282
});
103-
104-
onBFCacheRestore(() => {
105-
sessionValue = 0;
106-
fcpValue = -1;
107-
metric = initMetric('CLS', 0);
108-
report = bindReporter(onReportWrapped, metric, reportAllChanges);
109-
});
11083
}
11184
};

packages/tracing/src/browser/web-vitals/getFCP.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/tracing/src/browser/web-vitals/getFID.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,29 @@ import { bindReporter } from './lib/bindReporter';
1818
import { getVisibilityWatcher } from './lib/getVisibilityWatcher';
1919
import { initMetric } from './lib/initMetric';
2020
import { observe, PerformanceEntryHandler } from './lib/observe';
21-
import { onBFCacheRestore } from './lib/onBFCacheRestore';
2221
import { onHidden } from './lib/onHidden';
23-
import { firstInputPolyfill, resetFirstInputPolyfill } from './lib/polyfills/firstInputPolyfill';
24-
import { FirstInputPolyfillCallback, PerformanceEventTiming, ReportHandler } from './types';
22+
import { PerformanceEventTiming, ReportHandler } from './types';
2523

2624
export const getFID = (onReport: ReportHandler, reportAllChanges?: boolean): void => {
2725
const visibilityWatcher = getVisibilityWatcher();
28-
let metric = initMetric('FID');
26+
const metric = initMetric('FID');
2927
let report: ReturnType<typeof bindReporter>;
3028

3129
const entryHandler = (entry: PerformanceEventTiming): void => {
3230
// Only report if the page wasn't hidden prior to the first input.
33-
if (entry.startTime < visibilityWatcher.firstHiddenTime) {
31+
if (report && entry.startTime < visibilityWatcher.firstHiddenTime) {
3432
metric.value = entry.processingStart - entry.startTime;
3533
metric.entries.push(entry);
3634
report(true);
3735
}
3836
};
3937

4038
const po = observe('first-input', entryHandler as PerformanceEntryHandler);
41-
report = bindReporter(onReport, metric, reportAllChanges);
42-
4339
if (po) {
40+
report = bindReporter(onReport, metric, reportAllChanges);
4441
onHidden(() => {
4542
po.takeRecords().map(entryHandler as PerformanceEntryHandler);
4643
po.disconnect();
4744
}, true);
4845
}
49-
50-
// Only monitor bfcache restores if the browser supports FID natively.
51-
if (po) {
52-
onBFCacheRestore(() => {
53-
metric = initMetric('FID');
54-
report = bindReporter(onReport, metric, reportAllChanges);
55-
resetFirstInputPolyfill();
56-
firstInputPolyfill(entryHandler as FirstInputPolyfillCallback);
57-
});
58-
}
5946
};

packages/tracing/src/browser/web-vitals/getLCP.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { bindReporter } from './lib/bindReporter';
1818
import { getVisibilityWatcher } from './lib/getVisibilityWatcher';
1919
import { initMetric } from './lib/initMetric';
2020
import { observe, PerformanceEntryHandler } from './lib/observe';
21-
import { onBFCacheRestore } from './lib/onBFCacheRestore';
2221
import { onHidden } from './lib/onHidden';
2322
import { ReportHandler } from './types';
2423

@@ -37,7 +36,7 @@ const reportedMetricIDs: Set<string> = new Set();
3736

3837
export const getLCP = (onReport: ReportHandler, reportAllChanges?: boolean): void => {
3938
const visibilityWatcher = getVisibilityWatcher();
40-
let metric = initMetric('LCP');
39+
const metric = initMetric('LCP');
4140
let report: ReturnType<typeof bindReporter>;
4241

4342
const entryHandler = (entry: PerformanceEntry): void => {
@@ -77,17 +76,5 @@ export const getLCP = (onReport: ReportHandler, reportAllChanges?: boolean): voi
7776
});
7877

7978
onHidden(stopListening, true);
80-
81-
onBFCacheRestore(event => {
82-
metric = initMetric('LCP');
83-
report = bindReporter(onReport, metric, reportAllChanges);
84-
requestAnimationFrame(() => {
85-
requestAnimationFrame(() => {
86-
metric.value = performance.now() - event.timeStamp;
87-
reportedMetricIDs.add(metric.id);
88-
report(true);
89-
});
90-
});
91-
});
9279
}
9380
};

packages/tracing/src/browser/web-vitals/lib/getVisibilityWatcher.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { onBFCacheRestore } from './onBFCacheRestore';
1817
import { onHidden } from './onHidden';
1918

2019
let firstHiddenTime = -1;
@@ -40,17 +39,6 @@ export const getVisibilityWatcher = (): {
4039
// visibilityState.
4140
firstHiddenTime = initHiddenTime();
4241
trackChanges();
43-
44-
// Reset the time on bfcache restores.
45-
onBFCacheRestore(() => {
46-
// Schedule a task in order to track the `visibilityState` once it's
47-
// had an opportunity to change to visible in all browsers.
48-
// https://bugs.chromium.org/p/chromium/issues/detail?id=1133363
49-
setTimeout(() => {
50-
firstHiddenTime = initHiddenTime();
51-
trackChanges();
52-
}, 0);
53-
});
5442
}
5543
return {
5644
get firstHiddenTime() {

packages/tracing/src/browser/web-vitals/lib/onBFCacheRestore.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)