Skip to content

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

Go

fix(web): suppress deviceId hydration mismatch warning

Naiyuan Qing047de2b4319b
diff --git a/apps/web/app/components/chat.tsx b/apps/web/app/components/chat.tsx
index 260eeb93dd..9facb539e0 100644
--- a/apps/web/app/components/chat.tsx
+++ b/apps/web/app/components/chat.tsx
@@ -1,12 +1,55 @@
+"use client";
+
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 { cn } from "@multica/ui/lib/utils";
export function Chat() {
+ const deviceId = useDeviceStore((s) => s.deviceId);
+ const messages = useMessages();
+
return (
- <div className="h-dvh flex flex-col overflow-hidden">
- <header className="flex items-center p-2">
+ <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>
</header>
- <main className="flex-1 overflow-y-auto min-h-0"></main>
+
+ <main className="flex-1 overflow-y-auto min-h-0">
+ <div className="px-4 py-6 space-y-6 max-w-4xl mx-auto">
+ {messages.map((msg) => (
+ <div
+ key={msg.id}
+ className={cn(
+ "flex",
+ msg.role === "user" ? "justify-end" : "justify-start"
+ )}
+ >
+ <div
+ className={cn(
+ "max-w-[85%] rounded-2xl px-4 py-3",
+ msg.role === "user"
+ ? "bg-muted"
+ : ""
+ )}
+ >
+ <MemoizedMarkdown mode="minimal" id={msg.id}>
+ {msg.content}
+ </MemoizedMarkdown>
+ </div>
+ </div>
+ ))}
+ </div>
+ </main>
+
+ <footer className="w-full px-4 max-w-4xl mx-auto">
+ <ChatInput />
+ </footer>
</div>
);
}
diff --git a/apps/web/app/hooks/use-messages.ts b/apps/web/app/hooks/use-messages.ts
new file mode 100644
index 0000000000..801ea88bdc
--- /dev/null
+++ b/apps/web/app/hooks/use-messages.ts
@@ -0,0 +1,169 @@
+export type Message = {
+ id: string;
+ role: "user" | "assistant";
+ content: string;
+};
+
+const MOCK_MESSAGES: Message[] = [
+ {
+ id: "1",
+ role: "user",
+ content: "Hey! Can you explain how WebSocket connections work?",
+ },
+ {
+ id: "2",
+ role: "assistant",
+ content: `WebSocket provides **full-duplex** communication over a single TCP connection. Here's how it works:
+
+1. **Handshake** — The client sends an HTTP upgrade request
+2. **Connection** — The server agrees and upgrades the protocol
+3. **Messaging** — Both sides can send data at any time
+4. **Close** — Either side can close the connection
+
+A basic example in JavaScript:
+
+\`\`\`ts
+const ws = new WebSocket("wss://example.com/ws");
+
+ws.onopen = () => {
+ console.log("Connected");
+ ws.send(JSON.stringify({ type: "hello" }));
+};
+
+ws.onmessage = (event) => {
+ const data = JSON.parse(event.data);
+ console.log("Received:", data);
+};
+\`\`\`
+
+> Unlike HTTP, WebSocket keeps the connection alive so you don't need to poll.`,
+ },
+ {
+ id: "3",
+ role: "user",
+ content: "What's the difference between Socket.IO and raw WebSocket?",
+ },
+ {
+ id: "4",
+ role: "assistant",
+ content: `Great question! Here's a comparison:
+
+| Feature | WebSocket | Socket.IO |
+|---------|-----------|-----------|
+| Protocol | Standard WS | Custom on top of WS |
+| Reconnection | Manual | Automatic |
+| Rooms/Namespaces | No | Yes |
+| Fallback | None | HTTP long-polling |
+| Binary support | Yes | Yes |
+
+**When to use raw WebSocket:**
+- You need maximum performance
+- You're building a simple real-time feature
+- You want to keep dependencies minimal
+
+**When to use Socket.IO:**
+- You need automatic reconnection
+- You want room-based broadcasting
+- You need to support older browsers`,
+ },
+ {
+ id: "5",
+ role: "user",
+ content:
+ "Can you show me how to set up a simple Socket.IO server with event handling?",
+ },
+ {
+ id: "6",
+ role: "assistant",
+ content: `Sure! Here's a minimal Socket.IO server:
+
+\`\`\`ts
+import { Server } from "socket.io";
+
+const io = new Server(3000, {
+ cors: { origin: "*" },
+});
+
+io.on("connection", (socket) => {
+ console.log(\`Client connected: \${socket.id}\`);
+
+ socket.on("message", (data) => {
+ // Broadcast to all other clients
+ socket.broadcast.emit("message", {
+ from: socket.id,
+ ...data,
+ });
+ });
+
+ socket.on("disconnect", () => {
+ console.log(\`Client disconnected: \${socket.id}\`);
+ });
+});
+\`\`\`
+
+And the client side:
+
+\`\`\`ts
+import { io } from "socket.io-client";
+
+const socket = io("http://localhost:3000");
+
+socket.on("connect", () => {
+ socket.emit("message", { text: "Hello everyone!" });
+});
+
+socket.on("message", (data) => {
+ console.log("New message:", data);
+});
+\`\`\`
+
+That's it — the server handles connections, relays messages, and both sides can emit custom events freely.`,
+ },
+ {
+ id: "7",
+ role: "user",
+ content: "Thanks! How would I add authentication to this?",
+ },
+ {
+ id: "8",
+ role: "assistant",
+ content: `You can use Socket.IO's **middleware** to authenticate on connection:
+
+\`\`\`ts
+io.use((socket, next) => {
+ const token = socket.handshake.auth.token;
+
+ try {
+ const user = verifyJWT(token);
+ socket.data.user = user;
+ next();
+ } catch {
+ next(new Error("Authentication failed"));
+ }
+});
+\`\`\`
+
+On the client, pass the token when connecting:
+
+\`\`\`ts
+const socket = io("http://localhost:3000", {
+ auth: {
+ token: "your-jwt-token-here",
+ },
+});
+
+socket.on("connect_error", (err) => {
+ console.error("Auth failed:", err.message);
+});
+\`\`\`
+
+Key points:
+- The middleware runs **before** the \`connection\` event fires
+- You can attach user data to \`socket.data\` for later use
+- Failed auth rejects the connection entirely — no messages leak`,
+ },
+];
+
+export function useMessages(): Message[] {
+ return MOCK_MESSAGES;
+}
diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx
index 8a4248d15e..d55012c7ef 100644
--- a/apps/web/app/layout.tsx
+++ b/apps/web/app/layout.tsx
@@ -8,6 +8,7 @@ import {
} from "@multica/ui/components/ui/sidebar";
import { AppSidebar } from "@multica/ui/components/app-sidebar";
import { ThemeProvider } from "@multica/ui/components/theme-provider";
+import { Toaster } from "@multica/ui/components/ui/sonner";
const inter = Inter({ subsets: ["latin"], variable: "--font-sans" });
@@ -55,6 +56,7 @@ export default function RootLayout({
</SidebarInset>
</SidebarProvider>
</ThemeProvider>
+ <Toaster />
</body>
</html>
);
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 36d4807c66..49f3133c10 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -29,6 +29,7 @@
"remark-gfm": "^4.0.1",
"shadcn": "^3.7.0",
"shiki": "^3.21.0",
+ "sonner": "^2.0.7",
"tailwind-merge": "^3.4.0",
"tailwindcss": "^4",
"tw-animate-css": "^1.4.0"
diff --git a/packages/ui/src/components/chat-input.tsx b/packages/ui/src/components/chat-input.tsx
index 3559a5321e..7e0441dc93 100644
--- a/packages/ui/src/components/chat-input.tsx
+++ b/packages/ui/src/components/chat-input.tsx
@@ -17,7 +17,7 @@ export function ChatInput() {
};
return (
- <div className="bg-card rounded-xl p-3 border border-border">
+ <div className="bg-card rounded-xl p-3 pt-1 border border-border">
<textarea
ref={textareaRef}
rows={2}
diff --git a/packages/ui/src/components/ui/sonner.tsx b/packages/ui/src/components/ui/sonner.tsx
new file mode 100644
index 0000000000..e81f8388eb
--- /dev/null
+++ b/packages/ui/src/components/ui/sonner.tsx
@@ -0,0 +1,50 @@
+"use client"
+
+import { useTheme } from "next-themes"
+import { Toaster as Sonner, type ToasterProps } from "sonner"
+import { HugeiconsIcon } from "@hugeicons/react"
+import { CheckmarkCircle02Icon, InformationCircleIcon, Alert02Icon, MultiplicationSignCircleIcon, Loading03Icon } from "@hugeicons/core-free-icons"
+
+const Toaster = ({ ...props }: ToasterProps) => {
+ const { theme = "system" } = useTheme()
+
+ return (
+ <Sonner
+ theme={theme as ToasterProps["theme"]}
+ className="toaster group"
+ icons={{
+ success: (
+ <HugeiconsIcon icon={CheckmarkCircle02Icon} strokeWidth={2} className="size-4" />
+ ),
+ info: (
+ <HugeiconsIcon icon={InformationCircleIcon} strokeWidth={2} className="size-4" />
+ ),
+ warning: (
+ <HugeiconsIcon icon={Alert02Icon} strokeWidth={2} className="size-4" />
+ ),
+ error: (
+ <HugeiconsIcon icon={MultiplicationSignCircleIcon} strokeWidth={2} className="size-4" />
+ ),
+ loading: (
+ <HugeiconsIcon icon={Loading03Icon} strokeWidth={2} className="size-4 animate-spin" />
+ ),
+ }}
+ style={
+ {
+ "--normal-bg": "var(--popover)",
+ "--normal-text": "var(--popover-foreground)",
+ "--normal-border": "var(--border)",
+ "--border-radius": "var(--radius)",
+ } as React.CSSProperties
+ }
+ toastOptions={{
+ classNames: {
+ toast: "cn-toast",
+ },
+ }}
+ {...props}
+ />
+ )
+}
+
+export { Toaster }