Files
goclaw/ui/web/src/lib/utils.ts
T
Luan VuandLuvu182 4721cf26bd fix: replace crypto.randomUUID() with fallback for older browsers (#93)
Fixes #87. crypto.randomUUID() is unavailable in browsers older than
Chrome 92 / Firefox 95 / Safari 15.4, causing an uncaught TypeError
that crashes the React tree and renders a blank page when opening
builtin-tool settings or MCP grant dialogs.

Add a uniqueId() helper that uses crypto.randomUUID() when available
and falls back to a Math.random-based UUID v4 generator otherwise.

Co-authored-by: Luvu182 <208665161+Luvu182@users.noreply.github.com>
2026-03-09 12:56:35 +07:00

23 lines
691 B
TypeScript

import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
let counter = 0;
export function generateId(): string {
return `req-${++counter}-${Date.now()}`;
}
/** Generate a unique ID, with fallback for browsers lacking crypto.randomUUID. */
export function uniqueId(): string {
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
return crypto.randomUUID();
}
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
});
}