Skip to content

Commit eb1b971

Browse files
author
Matthias Kastner
committed
fix(client): avoid crypto.randomUUID() TypeError by adding uuid helper
Add a small, robust UUID helper and replace direct uses of crypto.randomUUID() in the client to avoid a runtime TypeError in browsers/environments that do not implement crypto.randomUUID which caused the frontend to crash and show the "Browser not supported / JavaScript changes.
1 parent bf51a6d commit eb1b971

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

client/src/lib/components/Toggle.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
label: string;
44
checked?: boolean;
55
}
6+
import { uuid } from '$lib/uuid';
67
78
let { label, checked = $bindable(), class: extraClass = '', ...rest }: Props = $props();
89
9-
const id = `toggle-${crypto.randomUUID()}`;
10+
const id = `toggle-${uuid()}`;
1011
</script>
1112

1213
<div class="flex items-center gap-2 {extraClass}">

client/src/lib/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { uuid } from './uuid';
2+
13
declare const umami: {
24
track: (event_name: string, data?: Record<string, any>) => void;
35
identify: (unique_id: string) => void;
@@ -11,7 +13,7 @@ export function initializeAnalytics(): void {
1113
const umamiIdKey = 'mvw_uuid';
1214
let uniqueId = localStorage.getItem(umamiIdKey);
1315
if (!uniqueId) {
14-
uniqueId = crypto.randomUUID();
16+
uniqueId = uuid();
1517
localStorage.setItem(umamiIdKey, uniqueId);
1618
}
1719
umami.identify(uniqueId);

0 commit comments

Comments
 (0)