Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

refactor(app): replace ref-mirror effects with render assignment (#4889)

Ansh Groverb00b21e720b2
diff --git a/apps/screenpipe-app-tauri/app/home/page.tsx b/apps/screenpipe-app-tauri/app/home/page.tsx
index a9d578c2f..8e5990937 100644
--- a/apps/screenpipe-app-tauri/app/home/page.tsx
+++ b/apps/screenpipe-app-tauri/app/home/page.tsx
@@ -417,8 +417,10 @@ function HomeContent() {
// Net effect: the sidebar slammed shut every time the user tried to
// open it during a meeting.
const sidebarPrevCollapsedRef = useRef<boolean | null>(null);
+ // Assigned during render (not in an effect): read only from the meeting
+ // focus-mode handler below, never during render.
const sidebarCollapsedRef = useRef(sidebarCollapsed);
- useEffect(() => { sidebarCollapsedRef.current = sidebarCollapsed; }, [sidebarCollapsed]);
+ sidebarCollapsedRef.current = sidebarCollapsed;
const handleMeetingFocusModeChange = useCallback(
(focused: boolean) => {
if (focused) {
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-session-runtime.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-session-runtime.ts
index 9cdda5a23..8e1979686 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-session-runtime.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-session-runtime.ts
@@ -136,17 +136,13 @@ export function useChatSessionRuntime({
if (storeChatIsLoading === false) setIsLoading(false);
}, [storeChatIsStreaming, storeChatIsLoading, setIsLoading, setIsStreaming]);
- useEffect(() => {
- isStreamingRef.current = isStreaming;
- }, [isStreaming, isStreamingRef]);
-
- useEffect(() => {
- isLoadingRef.current = isLoading;
- }, [isLoading, isLoadingRef]);
-
- useEffect(() => {
- messagesRef.current = messages;
- }, [messages, messagesRef]);
+ // Mirror the latest render values into their refs. These refs are read only
+ // from event-bus callbacks and the unmount snapshot below (never during
+ // render), so assigning during render — instead of in an effect — is the
+ // simpler, correct form and matches the pattern used in use-settings.tsx.
+ isStreamingRef.current = isStreaming;
+ isLoadingRef.current = isLoading;
+ messagesRef.current = messages;
useEffect(() => {
return () => {
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
index bd3097492..d04618e3b 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
@@ -344,10 +344,10 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {
// position. We CANNOT read this from inside the setCurrentIndex updater
// because React defers functional updaters until render — a value captured
// there is not yet set when the subscriber needs it.
+ // Assigned during render (not in an effect): the ref is read only from the
+ // store subscriber callback below, never during this component's render.
const currentIndexRef = useRef(currentIndex);
- useEffect(() => {
- currentIndexRef.current = currentIndex;
- }, [currentIndex]);
+ currentIndexRef.current = currentIndex;
useEffect(() => {
let prevTs = 0;