authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-09 22:46:38-07:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-09 22:50:23-07:00
log767de271e972b38de0633c04efcd62a929790b3e
tree050318b67163e729841e77136ab519ad6ad5f9a8
parent9d2c2cae375b6dfc7469c1ada07a109779364846

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

1 files changed, 3 insertions(+), 7 deletions(-)

apps/web/src/lib/utils.ts+3-7
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";1import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts";
2import { type CxOptions, cx } from "class-variance-authority";2import { type CxOptions, cx } from "class-variance-authority";
3import { twMerge } from "tailwind-merge";3import { twMerge } from "tailwind-merge";
4import * as Random from "effect/Random";
5import * as Effect from "effect/Effect";
46
5export function cn(...inputs: CxOptions) {7export function cn(...inputs: CxOptions) {
6 return twMerge(cx(inputs));8 return twMerge(cx(inputs));
...@@ -18,13 +20,7 @@ export function randomUUID(): string {...@@ -18,13 +20,7 @@ export function randomUUID(): string {
18 if (typeof crypto.randomUUID === "function") {20 if (typeof crypto.randomUUID === "function") {
19 return crypto.randomUUID();21 return crypto.randomUUID();
20 }22 }
21 // Fallback for non-secure contexts (plain HTTP on non-localhost)23 return Effect.runSync(Random.nextUUIDv4);
22 const bytes = new Uint8Array(16);
23 crypto.getRandomValues(bytes);
24 bytes[6] = (bytes[6] & 0x0f) | 0x40;
25 bytes[8] = (bytes[8] & 0x3f) | 0x80;
26 const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
27 return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
28}24}
2925
30export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());26export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());