forked from vercel/next.js
/
index.js
42 lines (37 loc) · 1021 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* global localStorage */
import { unstable_useWebVitalsReport } from 'next/vitals'
if (typeof navigator !== 'undefined') {
window.__BEACONS = window.__BEACONS || []
window.__BEACONS_COUNT = new Map()
navigator.sendBeacon = async function () {
const args = await Promise.all(
[...arguments].map((v) => {
if (v instanceof Blob) {
return v.text()
}
return v
})
)
window.__BEACONS.push(args)
}
}
export default () => {
// Below comment will be used for replacing exported report method with hook based one.
///* unstable_useWebVitalsReport
unstable_useWebVitalsReport((data) => {
const name = data.name || data.entryType
localStorage.setItem(
name,
data.value !== undefined ? data.value : data.startTime
)
const countMap = window.__BEACONS_COUNT
countMap.set(name, (countMap.get(name) || 0) + 1)
})
// unstable_useWebVitalsReport */
return (
<div>
<h1>Foo!</h1>
<h2>bar!</h2>
</div>
)
}