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): mirror latest values in render, not effects (ref-mirror sweep) (#4895)

Ansh Grover224b6e7ad085
diff --git a/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx b/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx
index 3bee00729..f549cf7a3 100644
--- a/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx
@@ -84,9 +84,8 @@ export function ChatHistoryView({
// Increment to invalidate in-flight loads from a previous tab/query.
const loadTokenRef = React.useRef(0);
- useEffect(() => {
- conversationsRef.current = conversations;
- }, [conversations]);
+ // Latest value mirrored during render (read only from the load-more callback).
+ conversationsRef.current = conversations;
const load = useCallback(
async (mode: "reset" | "append" = "reset") => {
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.ts
index e533ddf28..f7ec0de98 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.ts
@@ -67,9 +67,8 @@ export function useChatComposerShell() {
const [chipPrefixWidth, setChipPrefixWidth] = useState(0);
const [chipScrollTop, setChipScrollTop] = useState(0);
- useEffect(() => {
- inputValueRef.current = input;
- }, [input]);
+ // Latest value mirrored during render (consumed only from callbacks).
+ inputValueRef.current = input;
useLayoutEffect(() => {
if (!connectionChip) {
diff --git a/apps/screenpipe-app-tauri/components/meeting-notes/index.tsx b/apps/screenpipe-app-tauri/components/meeting-notes/index.tsx
index 68b4a792a..2877cc06e 100644
--- a/apps/screenpipe-app-tauri/components/meeting-notes/index.tsx
+++ b/apps/screenpipe-app-tauri/components/meeting-notes/index.tsx
@@ -149,9 +149,8 @@ export function MeetingNotesSection({
// depend on `fetchPage` (intentionally stable) and shouldn't re-bind
// when the query changes, but they still need to reuse it.
const appliedQueryRef = useRef(appliedQuery);
- useEffect(() => {
- appliedQueryRef.current = appliedQuery;
- }, [appliedQuery]);
+ // Latest value mirrored during render (read only from fetch callbacks).
+ appliedQueryRef.current = appliedQuery;
// Track an in-flight open-meeting-note request so the "selection
// vanished" effect below doesn't reset selectedId during the brief
@@ -223,9 +222,8 @@ export function MeetingNotesSection({
// setContent, which re-parses the markdown and visually tightens loose
// lists and paragraph spacing.
const selectedIdRef = useRef(selectedId);
- useEffect(() => {
- selectedIdRef.current = selectedId;
- }, [selectedId]);
+ // Latest value mirrored during render (read only from callbacks).
+ selectedIdRef.current = selectedId;
useEffect(() => {
const handler = () => {
if (document.visibilityState !== "visible") return;
@@ -316,9 +314,8 @@ export function MeetingNotesSection({
// identity changes (e.g. after the user expands the sidebar by hand,
// which is exactly the wrong moment to re-collapse it).
const onFocusModeChangeRef = useRef(onFocusModeChange);
- useEffect(() => {
- onFocusModeChangeRef.current = onFocusModeChange;
- }, [onFocusModeChange]);
+ // Latest callback mirrored during render (invoked only from callbacks below).
+ onFocusModeChangeRef.current = onFocusModeChange;
useEffect(() => {
onFocusModeChangeRef.current?.(selectedId !== null);
}, [selectedId]);
diff --git a/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsx b/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsx
index f9ceabf98..8495a0795 100644
--- a/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsx
+++ b/apps/screenpipe-app-tauri/components/meeting-notes/note-editor.tsx
@@ -170,9 +170,9 @@ function NoteEditor(
// whether an incoming `value` originated from the editor itself (skip) vs
// an external source like the server or AI summary (apply).
const lastEmittedRef = useRef<string | null>(null);
- useEffect(() => {
- onChangeRef.current = onChange;
- }, [onChange]);
+ // Latest callback mirrored during render (invoked only from the editor's
+ // onUpdate handler).
+ onChangeRef.current = onChange;
const insertImages = useCallback(
(dataUrls: string[], at?: { clientX: number; clientY: number }) => {