mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
chore: upgrade web vitals
This commit is contained in:
1 parent
d90e13396c
commit
ddc5f375be
4 files changed
+33
-24
No files matched your search
Generated
+7
-7
@@ -14,7 +14,7 @@
|
||||
"echarts": "^5.4.0",
|
||||
"prismjs": "^1.29.0",
|
||||
"tippy.js": "^6.3.7",
|
||||
"web-vitals": "^2.1.4"
|
||||
"web-vitals": "^3.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.26.1",
|
||||
@@ -7531,9 +7531,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/web-vitals": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-2.1.4.tgz",
|
||||
"integrity": "sha512-sVWcwhU5mX6crfI5Vd2dC4qchyTqxV8URinzt25XqVh+bHEPGH4C3NPrNionCP7Obx59wrYEbNlw4Z8sjALzZg=="
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-3.0.3.tgz",
|
||||
"integrity": "sha512-8K6cl3alkVhwv7RQm3WAWFzvP9dBTH4CwOE7G3DfQDEnBJTdtNgX5XMqgE7aE79wac/kJ8fHWftUfH3AVxxbBw=="
|
||||
},
|
||||
"node_modules/webidl-conversions": {
|
||||
"version": "7.0.0",
|
||||
@@ -13334,9 +13334,9 @@
|
||||
}
|
||||
},
|
||||
"web-vitals": {
|
||||
"version": "2.1.4",
|
||||
"resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-2.1.4.tgz",
|
||||
"integrity": "sha512-sVWcwhU5mX6crfI5Vd2dC4qchyTqxV8URinzt25XqVh+bHEPGH4C3NPrNionCP7Obx59wrYEbNlw4Z8sjALzZg=="
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/web-vitals/-/web-vitals-3.0.3.tgz",
|
||||
"integrity": "sha512-8K6cl3alkVhwv7RQm3WAWFzvP9dBTH4CwOE7G3DfQDEnBJTdtNgX5XMqgE7aE79wac/kJ8fHWftUfH3AVxxbBw=="
|
||||
},
|
||||
"webidl-conversions": {
|
||||
"version": "7.0.0",
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
"echarts": "^5.4.0",
|
||||
"prismjs": "^1.29.0",
|
||||
"tippy.js": "^6.3.7",
|
||||
"web-vitals": "^2.1.4"
|
||||
"web-vitals": "^3.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.26.1",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { getCLS, getFCP, getFID, getLCP, getTTFB, type Metric } from 'web-vitals';
|
||||
import { page } from '$app/stores';
|
||||
import { get } from 'svelte/store';
|
||||
import type { Metric } from 'web-vitals';
|
||||
|
||||
type Options = {
|
||||
params:
|
||||
@@ -57,14 +59,19 @@ function sendToAnalytics(metric: Metric, options: Options) {
|
||||
});
|
||||
}
|
||||
|
||||
export function webVitals(options: Options) {
|
||||
export function reportWebVitals(metric: Metric) {
|
||||
try {
|
||||
getFID((metric) => sendToAnalytics(metric, options));
|
||||
getTTFB((metric) => sendToAnalytics(metric, options));
|
||||
getLCP((metric) => sendToAnalytics(metric, options));
|
||||
getCLS((metric) => sendToAnalytics(metric, options));
|
||||
getFCP((metric) => sendToAnalytics(metric, options));
|
||||
sendToAnalytics(metric, createWebVitalsOptions());
|
||||
} catch (err) {
|
||||
console.error('[Analytics]', err);
|
||||
}
|
||||
}
|
||||
|
||||
function createWebVitalsOptions(): Options {
|
||||
const ctx = get(page);
|
||||
return {
|
||||
path: ctx.url.pathname,
|
||||
params: ctx.params,
|
||||
analyticsId: window.VERCEL_ANALYTICS_ID || ''
|
||||
};
|
||||
}
|
||||
@@ -3,13 +3,14 @@
|
||||
import { page } from '$app/stores';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { redirectTo } from '$lib/stores/organization';
|
||||
import { onCLS, onFID, onLCP } from 'web-vitals';
|
||||
import { reportWebVitals } from '$lib/helpers/vitals';
|
||||
import { onMount } from 'svelte';
|
||||
import { base } from '$app/paths';
|
||||
import { browser, dev } from '$app/environment';
|
||||
import { app } from '$lib/stores/app';
|
||||
import Notifications from '$lib/layout/notifications.svelte';
|
||||
import Loading from './_loading.svelte';
|
||||
import { webVitals } from '$lib/helpers/vitals';
|
||||
|
||||
let loaded = false;
|
||||
|
||||
@@ -21,6 +22,15 @@
|
||||
const acceptedRoutes = ['/login', '/register', '/recover', '/invite'];
|
||||
|
||||
onMount(async () => {
|
||||
/**
|
||||
* Reporting Web Vitals.
|
||||
*/
|
||||
if (!dev && window.VERCEL_ANALYTICS_ID) {
|
||||
onCLS(reportWebVitals);
|
||||
onFID(reportWebVitals);
|
||||
onLCP(reportWebVitals);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!$user) {
|
||||
await user.fetchUser();
|
||||
@@ -38,14 +48,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
$: if (!dev && browser && window.VERCEL_ANALYTICS_ID) {
|
||||
webVitals({
|
||||
path: $page.url.pathname,
|
||||
params: $page.params,
|
||||
analyticsId: window.VERCEL_ANALYTICS_ID
|
||||
});
|
||||
}
|
||||
|
||||
$: {
|
||||
if (browser) {
|
||||
if ($app.theme === 'auto') {
|
||||
|
||||
Reference in new issue
Block a user