Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(web): replace Zustand device store with local useDeviceId hook

Naiyuan Qing5f367fb6b75a
diff --git a/apps/web/app/components/chat.tsx b/apps/web/app/components/chat.tsx
index 6702015757..990b3bcb7c 100644
--- a/apps/web/app/components/chat.tsx
+++ b/apps/web/app/components/chat.tsx
@@ -4,13 +4,13 @@ import { useRef } from "react";
import { SidebarTrigger } from "@multica/ui/components/ui/sidebar";
import { ChatInput } from "@multica/ui/components/chat-input";
import { MemoizedMarkdown } from "@multica/ui/components/markdown";
-import { useDeviceStore } from "@multica/store";
import { useMessages } from "../hooks/use-messages";
+import { useDeviceId } from "../hooks/use-device-id";
import { useScrollFade } from "../hooks/use-scroll-fade";
import { cn } from "@multica/ui/lib/utils";
export function Chat() {
- const deviceId = useDeviceStore((s) => s.deviceId);
+ const deviceId = useDeviceId();
const messages = useMessages();
const mainRef = useRef<HTMLElement>(null);
const fadeStyle = useScrollFade(mainRef);
@@ -19,8 +19,8 @@ export function Chat() {
<div className="h-dvh flex flex-col overflow-hidden w-full">
<header className="flex items-center gap-2 p-2">
<SidebarTrigger />
- <span className="text-xs text-muted-foreground font-mono" suppressHydrationWarning>
- {deviceId.slice(0, 8)}
+ <span className="text-xs text-muted-foreground font-mono">
+ {deviceId ? deviceId.slice(0, 8) : "\u00A0"}
</span>
</header>
diff --git a/apps/web/app/hooks/use-device-id.ts b/apps/web/app/hooks/use-device-id.ts
new file mode 100644
index 0000000000..5b76578f4b
--- /dev/null
+++ b/apps/web/app/hooks/use-device-id.ts
@@ -0,0 +1,19 @@
+import { useState, useEffect } from "react"
+import { v7 as uuidv7 } from "uuid"
+
+const STORAGE_KEY = "multica-device-id"
+
+export function useDeviceId(): string {
+ const [deviceId, setDeviceId] = useState("")
+
+ useEffect(() => {
+ let id = localStorage.getItem(STORAGE_KEY)
+ if (!id) {
+ id = uuidv7()
+ localStorage.setItem(STORAGE_KEY, id)
+ }
+ setDeviceId(id)
+ }, [])
+
+ return deviceId
+}
diff --git a/apps/web/package.json b/apps/web/package.json
index cf897d6523..b89ba803d5 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -11,6 +11,7 @@
"dependencies": {
"@multica/store": "workspace:*",
"@multica/ui": "workspace:*",
+ "uuid": "^13.0.0",
"@hugeicons/core-free-icons": "^3.1.1",
"@hugeicons/react": "^1.1.4",
"next": "16.1.6",
diff --git a/packages/store/package.json b/packages/store/package.json
index a25fe7f591..2837c0c7d4 100644
--- a/packages/store/package.json
+++ b/packages/store/package.json
@@ -8,7 +8,6 @@
"./*": "./src/*.ts"
},
"dependencies": {
- "uuid": "^13.0.0",
"zustand": "catalog:"
},
"devDependencies": {
diff --git a/packages/store/src/device.ts b/packages/store/src/device.ts
deleted file mode 100644
index 9f38e3b928..0000000000
--- a/packages/store/src/device.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { create } from 'zustand'
-import { persist } from 'zustand/middleware'
-import { v7 as uuidv7 } from 'uuid'
-
-interface DeviceState {
- deviceId: string
-}
-
-export const useDeviceStore = create<DeviceState>()(
- persist(
- () => ({
- deviceId: uuidv7(),
- }),
- { name: 'multica-device' }
- )
-)
diff --git a/packages/store/src/index.ts b/packages/store/src/index.ts
index dfb71b12d7..778a5959e8 100644
--- a/packages/store/src/index.ts
+++ b/packages/store/src/index.ts
@@ -1,2 +1 @@
export { useCounterStore } from './counter'
-export { useDeviceStore } from './device'
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d9ea178eaa..071cbb396e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -223,6 +223,9 @@ importers:
react-dom:
specifier: 'catalog:'
version: 19.2.3([email protected])
+ uuid:
+ specifier: ^13.0.0
+ version: 13.0.0
devDependencies:
'@types/node':
specifier: 'catalog:'
@@ -261,9 +264,6 @@ importers:
packages/store:
dependencies:
- uuid:
- specifier: ^13.0.0
- version: 13.0.0
zustand:
specifier: 'catalog:'