Skip to content

Commit 1fb759d

Browse files
authored
fix(web): use uuid for client-generated ids (#3698)
1 parent aa6fe2c commit 1fb759d

7 files changed

Lines changed: 17 additions & 10 deletions

File tree

apps/web/src/components/app-builder/AppBuilderChat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import React, {
2222
} from 'react';
2323
import { User, ArrowDown, ChevronRight, ChevronDown, SquarePen } from 'lucide-react';
2424
import { format } from 'date-fns';
25+
import { v4 as uuidv4 } from 'uuid';
2526
import { TimeAgo } from '@/components/shared/TimeAgo';
2627
import AssistantLogo from '@/components/AssistantLogo';
2728
import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip';
@@ -455,7 +456,7 @@ export function AppBuilderChat({ organizationId }: AppBuilderChatProps) {
455456
const scrollContainerRef = useRef<HTMLDivElement>(null);
456457
const [showScrollButton, setShowScrollButton] = useState(false);
457458
const [shouldAutoScroll, setShouldAutoScroll] = useState(true);
458-
const [messageUuid, setMessageUuid] = useState(() => crypto.randomUUID());
459+
const [messageUuid, setMessageUuid] = useState(() => uuidv4());
459460
const [selectedModel, setSelectedModel] = useState<string>(projectModel ?? '');
460461
const [hasImages, setHasImages] = useState(false);
461462
// Track the initial projectModel to detect when a new project loads
@@ -627,7 +628,7 @@ export function AppBuilderChat({ organizationId }: AppBuilderChatProps) {
627628
}
628629
manager.sendMessage(value, images, selectedModel || undefined);
629630
// PromptInput clears itself internally after successful submit
630-
setMessageUuid(crypto.randomUUID());
631+
setMessageUuid(uuidv4());
631632
},
632633
[manager, selectedModel, pendingNewSession, sessions.length]
633634
);

apps/web/src/components/app-builder/AppBuilderLanding.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import { useState, useEffect, useMemo, useCallback } from 'react';
1616
import { Clock, FolderOpen, Search, ChevronRight, Trash2, Users, User } from 'lucide-react';
17+
import { v4 as uuidv4 } from 'uuid';
1718
import { Button } from '@/components/ui/button';
1819
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
1920
import { Input } from '@/components/ui/input';
@@ -527,7 +528,7 @@ export function AppBuilderLanding({ organizationId, onProjectCreated }: AppBuild
527528
const [hasImages, setHasImages] = useState(false);
528529
const [isCreatingFromTemplate, setIsCreatingFromTemplate] = useState(false);
529530
// Generate a stable messageUuid for image uploads - this identifies this initial prompt message
530-
const [messageUuid] = useState(() => crypto.randomUUID());
531+
const [messageUuid] = useState(() => uuidv4());
531532
const trpc = useTRPC();
532533

533534
// Fetch eligibility to check if user can use App Builder

apps/web/src/components/cloud-agent-next/CloudChatPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useSearchParams } from 'next/navigation';
66
import { useMutation, useQueryClient } from '@tanstack/react-query';
77
import { useTRPC } from '@/lib/trpc/utils';
88
import { ArrowDown, GitBranch } from 'lucide-react';
9+
import { v4 as uuidv4 } from 'uuid';
910

1011
import type { KiloSessionId } from '@/lib/cloud-agent-sdk';
1112
import { useManager } from './CloudAgentProvider';
@@ -224,7 +225,7 @@ export default function CloudChatPage({ organizationId }: CloudChatPageProps) {
224225

225226
const setSessionConfig = useSetAtom(manager.atoms.sessionConfig);
226227

227-
const [attachmentMessageUuid] = useState(() => crypto.randomUUID());
228+
const [attachmentMessageUuid] = useState(() => uuidv4());
228229
const [workspaceTabs, setWorkspaceTabs] = useState(createWorkspaceTabsState);
229230
const [terminalStatuses, setTerminalStatuses] = useState<
230231
Record<string, TerminalStatusSummary | undefined>
@@ -449,7 +450,7 @@ export default function CloudChatPage({ organizationId }: CloudChatPageProps) {
449450
}, [setSoundEnabled]);
450451

451452
const handleCreateTerminalTab = useCallback(() => {
452-
const terminalId = crypto.randomUUID();
453+
const terminalId = uuidv4();
453454
setWorkspaceTabs(state => addTerminalTab(state, terminalId));
454455
}, []);
455456

apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Link from 'next/link';
66
import { useRouter } from 'next/navigation';
77
import { useAtom, useSetAtom } from 'jotai';
88
import { toast } from 'sonner';
9+
import { v4 as uuidv4 } from 'uuid';
910
import {
1011
AlertCircle,
1112
Brain,
@@ -189,7 +190,7 @@ export function NewSessionPanel({ organizationId, isDevcontainerAvailable }: New
189190
const [isRepoUserSelected, setIsRepoUserSelected] = useState(false);
190191
const [showRepositoryRequiredMessage, setShowRepositoryRequiredMessage] = useState(false);
191192
const [isPreparing, setIsPreparing] = useState(false);
192-
const [attachmentMessageUuid, setAttachmentMessageUuid] = useState(() => crypto.randomUUID());
193+
const [attachmentMessageUuid, setAttachmentMessageUuid] = useState(() => uuidv4());
193194

194195
// ---------------------------------------------------------------------------
195196
// GitHub identity awareness
@@ -819,7 +820,7 @@ export function NewSessionPanel({ organizationId, isDevcontainerAvailable }: New
819820
});
820821

821822
attachmentUpload.clearAttachments();
822-
setAttachmentMessageUuid(crypto.randomUUID());
823+
setAttachmentMessageUuid(uuidv4());
823824

824825
const basePath = organizationId ? `/organizations/${organizationId}/cloud` : '/cloud';
825826
router.push(`${basePath}/chat?sessionId=${result.kiloSessionId}`);

apps/web/src/components/cloud-agent/ProfilesListDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { useState, useEffect, useRef } from 'react';
55
import { useQuery } from '@tanstack/react-query';
66
import { toast } from 'sonner';
7+
import { v4 as uuidv4 } from 'uuid';
78
import {
89
FolderCog,
910
Star,
@@ -1184,7 +1185,7 @@ type VarsTabProps = {
11841185
type DraftVar = { id: string; key: string; value: string; isSecret: boolean; showValue: boolean };
11851186

11861187
const makeDraft = (partial?: Partial<DraftVar>): DraftVar => ({
1187-
id: crypto.randomUUID(),
1188+
id: uuidv4(),
11881189
key: '',
11891190
value: '',
11901191
isSecret: false,

apps/web/src/hooks/useCloudAgentAttachmentUpload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useCallback, useEffect, useRef, useState } from 'react';
44
import { useMutation } from '@tanstack/react-query';
55
import { toast } from 'sonner';
6+
import { v4 as uuidv4 } from 'uuid';
67
import { useTRPC } from '@/lib/trpc/utils';
78
import {
89
CLOUD_AGENT_ATTACHMENT_ALLOWED_TYPES,
@@ -329,7 +330,7 @@ export function useCloudAgentAttachmentUpload(
329330
const kind = contentType.startsWith('image/') ? ('image' as const) : ('document' as const);
330331
return [
331332
{
332-
id: crypto.randomUUID(),
333+
id: uuidv4(),
333334
file,
334335
contentType,
335336
kind,

apps/web/src/hooks/useImageUpload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
44
import { useMutation } from '@tanstack/react-query';
55
import { useTRPC } from '@/lib/trpc/utils';
66
import { toast } from 'sonner';
7+
import { v4 as uuidv4 } from 'uuid';
78
import {
89
APP_BUILDER_IMAGE_MAX_COUNT,
910
APP_BUILDER_IMAGE_MAX_SIZE_BYTES,
@@ -415,7 +416,7 @@ export function useImageUpload(options: UseImageUploadOptions): UseImageUploadRe
415416
}
416417

417418
const processingImages = filesToAdd.map(file => ({
418-
id: crypto.randomUUID(),
419+
id: uuidv4(),
419420
file,
420421
previewUrl: URL.createObjectURL(file),
421422
status: 'processing' as const,

0 commit comments

Comments
 (0)