Use Effect UUID generator as randomUUID fallback

- Replace manual UUID byte formatting fallback in `apps/web/src/lib/utils.ts`
- Use `Effect.runSync(Random.nextUUIDv4)` when `crypto.randomUUID` is unavailable
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-03-09 22:50:23 -07:00
1 parent 9d2c2cae37
commit 767de271e9
1 file changed
+3 -7
+3 -7
View File
@@ -1,6 +1,8 @@
import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
import { type CxOptions, cx } from "class-variance-authority";
import { twMerge } from "tailwind-merge";
import * as Random from "effect/Random";
import * as Effect from "effect/Effect";
export function cn(...inputs: CxOptions) {
return twMerge(cx(inputs));
@@ -18,13 +20,7 @@ export function randomUUID(): string {
if (typeof crypto.randomUUID === "function") {
return crypto.randomUUID();
}
// Fallback for non-secure contexts (plain HTTP on non-localhost)
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
bytes[6] = (bytes[6] & 0x0f) | 0x40;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
return Effect.runSync(Random.nextUUIDv4);
}
export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());