mirror of
https://github.com/basketikun/infinite-canvas.git
synced 2026-08-06 01:14:36 +08:00
feat(id): replace crypto.randomUUID with nanoid for unique ID generation
This commit is contained in:
@@ -9,3 +9,6 @@ data/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.idea
|
.idea
|
||||||
web/dist
|
web/dist
|
||||||
|
|
||||||
|
**/dist
|
||||||
|
web/public/plugins
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## v0.7.1 - 2026-07-15
|
||||||
|
|
||||||
|
+ [修复] 修复通过 `crypto.randomUUID` 不可用导致页面白屏报错的问题,改用 nanoid 生成 id。
|
||||||
|
|
||||||
## v0.7.0 - 2026-07-14
|
## v0.7.0 - 2026-07-14
|
||||||
|
|
||||||
+ [新增] Agent 对话消息改用 streamdown 流式渲染,提升Markdown 内容展示效果。
|
+ [新增] Agent 对话消息改用 streamdown 流式渲染,提升Markdown 内容展示效果。
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import copyToClipboard from "copy-to-clipboard";
|
|||||||
import { Copy, FolderOpen, History, KeyRound, Link2, LoaderCircle, PlugZap, Plus, RefreshCw, Square, Terminal, Trash2 } from "lucide-react";
|
import { Copy, FolderOpen, History, KeyRound, Link2, LoaderCircle, PlugZap, Plus, RefreshCw, Square, Terminal, Trash2 } from "lucide-react";
|
||||||
|
|
||||||
import { canvasThemes } from "@/lib/canvas-theme";
|
import { canvasThemes } from "@/lib/canvas-theme";
|
||||||
|
import { randomId } from "@/lib/utils";
|
||||||
import { useThemeStore } from "@/stores/use-theme-store";
|
import { useThemeStore } from "@/stores/use-theme-store";
|
||||||
import { useUserStore } from "@/stores/use-user-store";
|
import { useUserStore } from "@/stores/use-user-store";
|
||||||
import { useAgentStore, type AgentAttachment, type AgentChatItem, type AgentEventLog, type AgentPanelTab, type AgentPendingToolCall, type AgentThreadSummary } from "@/stores/use-agent-store";
|
import { useAgentStore, type AgentAttachment, type AgentChatItem, type AgentEventLog, type AgentPanelTab, type AgentPendingToolCall, type AgentThreadSummary } from "@/stores/use-agent-store";
|
||||||
@@ -54,7 +55,7 @@ export function CanvasLocalAgentPanel({ embedded, headless, autoConnect }: { emb
|
|||||||
const connectedRef = useRef(false);
|
const connectedRef = useRef(false);
|
||||||
const errorLoggedRef = useRef(false);
|
const errorLoggedRef = useRef(false);
|
||||||
const attachmentUrlsRef = useRef(new Set<string>());
|
const attachmentUrlsRef = useRef(new Set<string>());
|
||||||
const clientIdRef = useRef(typeof crypto === "undefined" ? `${Date.now()}` : crypto.randomUUID());
|
const clientIdRef = useRef(randomId());
|
||||||
const endpoint = useMemo(() => url.trim().replace(/\/$/, ""), [url]);
|
const endpoint = useMemo(() => url.trim().replace(/\/$/, ""), [url]);
|
||||||
const urlAgentAutoConnect = searchParams.has("agentUrl") && searchParams.has("agentToken");
|
const urlAgentAutoConnect = searchParams.has("agentUrl") && searchParams.has("agentToken");
|
||||||
const loadThreads = useCallback(async () => {
|
const loadThreads = useCallback(async () => {
|
||||||
@@ -1045,7 +1046,7 @@ function formatThreadTime(value?: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createId() {
|
function createId() {
|
||||||
return typeof crypto === "undefined" ? `${Date.now()}-${Math.random()}` : crypto.randomUUID();
|
return randomId();
|
||||||
}
|
}
|
||||||
|
|
||||||
function clamp(value: number, min: number, max: number) {
|
function clamp(value: number, min: number, max: number) {
|
||||||
|
|||||||
@@ -1,6 +1,18 @@
|
|||||||
import { clsx, type ClassValue } from "clsx";
|
import { clsx, type ClassValue } from "clsx";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs));
|
return twMerge(clsx(inputs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a unique id.
|
||||||
|
*
|
||||||
|
* Avoid `crypto.randomUUID`, which is only exposed in secure contexts (HTTPS or
|
||||||
|
* localhost) — over plain HTTP it is undefined and throws. `nanoid` works in any
|
||||||
|
* context.
|
||||||
|
*/
|
||||||
|
export function randomId(): string {
|
||||||
|
return nanoid();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user