[web] Avoid double indexing of client side referencing (#28235)

* [web] Move chat client id to shared module

* [web] Avoid double indexing of client references

GitOrigin-RevId: 993930e66fdc9952649e3e8d345c70dd37516121
This commit is contained in:
Mathias Jakobsen
2025-09-08 08:05:14 +00:00
committed by Copybot
parent 644db1722e
commit 442c1952ab
7 changed files with 37 additions and 17 deletions
@@ -8,8 +8,7 @@ import {
useRef,
FC,
} from 'react'
import { v4 as uuid } from 'uuid'
import clientIdGenerator from '@/utils/client-id'
import { useUserContext } from '../../../shared/context/user-context'
import { useProjectContext } from '../../../shared/context/project-context'
import { getJSON, postJSON } from '../../../infrastructure/fetch-json'
@@ -78,11 +77,6 @@ type Action =
error: any
}
// Wrap uuid in an object method so that it can be stubbed
export const chatClientIdGenerator = {
generate: () => uuid(),
}
let nextChatMessageId = 1
function generateChatMessageId() {
@@ -201,7 +195,7 @@ export const ChatProvider: FC<React.PropsWithChildren> = ({ children }) => {
const clientId = useRef<string>()
if (clientId.current === undefined) {
clientId.current = chatClientIdGenerator.generate()
clientId.current = clientIdGenerator.get()
}
const user = useUserContext()
const { projectId } = useProjectContext()