mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-05 06:13:51 +00:00
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>
23 lines
691 B
TypeScript
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);
|
|
});
|
|
}
|