From b8c5537ae28a2dc8bbdf75bf530eef0e7d4e28d9 Mon Sep 17 00:00:00 2001 From: DigHuang <114602213+DigHuang@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:32:32 +0800 Subject: [PATCH] fix(tracker): split useEffect hooks avoid resend, and dynamically retrieve tracker user_id --- .../agent/components/agent-view/common-agent-area.tsx | 11 +++-------- frontend/src/lib/tracker.ts | 4 +--- frontend/src/store/plugin/tauri-store-state.ts | 7 ++----- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/agent/components/agent-view/common-agent-area.tsx b/frontend/src/app/agent/components/agent-view/common-agent-area.tsx index e71639a84..9881b48a8 100644 --- a/frontend/src/app/agent/components/agent-view/common-agent-area.tsx +++ b/frontend/src/app/agent/components/agent-view/common-agent-area.tsx @@ -168,20 +168,15 @@ const CommonAgentAreaContent: FC = ({ agentName }) => { if (curConversationId !== conversationId) { setCurConversationId(conversationId); } + }, [setCurConversationId, curConversationId, conversationId]); + useEffect(() => { if (inputValueFromLocation) { sendMessage(inputValueFromLocation); // Clear the state after using it once to prevent re-triggering on page refresh navigate(".", { replace: true, state: {} }); } - }, [ - sendMessage, - setCurConversationId, - curConversationId, - navigate, - conversationId, - inputValueFromLocation, - ]); + }, [inputValueFromLocation, navigate, sendMessage]); const [inputValue, setInputValue] = useState(""); const { currentSection } = useMultiSection(); diff --git a/frontend/src/lib/tracker.ts b/frontend/src/lib/tracker.ts index 8d790b3f7..fb1be166a 100644 --- a/frontend/src/lib/tracker.ts +++ b/frontend/src/lib/tracker.ts @@ -28,7 +28,6 @@ interface TrackerConfig { } interface TrackingParams { - user_id: string; client_id: string; os: string; [key: string]: unknown; @@ -41,7 +40,6 @@ class Tracker { constructor(config: TrackerConfig) { this.config = config; this.params = { - user_id: useSystemStore.getState().id, client_id: "", os: "", }; @@ -60,7 +58,6 @@ class Tracker { ); this.params = { - ...this.params, client_id: clientId, os: systemInfo, }; @@ -77,6 +74,7 @@ class Tracker { const payload = { event, + user_id: useSystemStore.getState().id, ...this.params, ...params, }; diff --git a/frontend/src/store/plugin/tauri-store-state.ts b/frontend/src/store/plugin/tauri-store-state.ts index ece414141..c87bc20cb 100644 --- a/frontend/src/store/plugin/tauri-store-state.ts +++ b/frontend/src/store/plugin/tauri-store-state.ts @@ -1,3 +1,4 @@ +import { isTauri } from "@tauri-apps/api/core"; import { load, type Store } from "@tauri-apps/plugin-store"; import type { StateStorage } from "zustand/middleware"; import { debounce } from "@/hooks/use-debounce"; @@ -23,11 +24,7 @@ export class TauriStoreState implements StateStorage { return; } - const tauriInternals = ( - window as Window & { __TAURI_INTERNALS__?: unknown } - ).__TAURI_INTERNALS__; - - if (!tauriInternals) { + if (!isTauri()) { // Running in a regular browser; fall back to default persist storage. return; }