From 767de271e972b38de0633c04efcd62a929790b3e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 9 Mar 2026 22:46:38 -0700 Subject: [PATCH] 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 --- apps/web/src/lib/utils.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.ts index 9c2311ba8fd1d83ff4684943812562b1123d86eb..08a5de91e6619470d1b7d71d49fd1dea79b94ce5 100644 --- a/apps/web/src/lib/utils.ts +++ b/apps/web/src/lib/utils.ts @@ -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()); -- 2.54.0