Skip to content

Conversation

@ukos-git
Copy link

@ukos-git ukos-git commented Dec 7, 2025

The client currently calls crypto.randomUUID() directly (notably in initializeAnalytics and Toggle). In environments where crypto.randomUUID is not available, this throws a TypeError and crashes the frontend, causing the app to show a fallback "Browser not supported / JavaScript disabled" banner.
This PR introduces a small uuid() helper and replaces direct calls to crypto.randomUUID() with uuid(), preventing the crash and improving compatibility.
Changes

client/src/lib/uuid.ts (new)
Adds uuid(): string which:
returns native crypto.randomUUID() if present
otherwise builds an RFC4122 v4 UUID using crypto.getRandomValues() if available
otherwise uses a last-resort Math.random() based UUID
client/src/lib/utils.ts (modified)
import { uuid } from '$lib/uuid';
replace uniqueId = crypto.randomUUID() with uniqueId = uuid();
client/src/lib/components/Toggle.svelte (modified)
import { uuid } from '$lib/uuid';
replace toggle id generation to use uuid()
Rationale

Avoids runtime crash on browsers/environments without crypto.randomUUID
Keeps behavior deterministic: still uses secure randomness when available
Minimal change surface and no new runtime dependency
Risk and backward compatibility

The only functional change is how the UUID is created when the native function is missing.
Analytics ID stored in localStorage continues to be a string UUID, so downstream code continues to work.
If maintainers prefer a global polyfill for crypto.randomUUID(), that can be done instead; this PR chooses an explicit helper to avoid mutating global state.

Screenshot From 2025-12-07 19-20-48

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.
@ukos-git ukos-git force-pushed the bugfix/uuid_not_available branch from eb1b971 to 323b79d Compare December 7, 2025 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant