Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix: avoid state updates after page teardown

Steven Enamakel9b6ad4724ce2
diff --git a/app/src/components/intelligence/MemorySourcesRegistry.tsx b/app/src/components/intelligence/MemorySourcesRegistry.tsx
index 5505a03d5b..343f4709da 100644
--- a/app/src/components/intelligence/MemorySourcesRegistry.tsx
+++ b/app/src/components/intelligence/MemorySourcesRegistry.tsx
@@ -98,6 +98,7 @@ export function MemorySourcesRegistry({
const [allInModalOpen, setAllInModalOpen] = useState(false);
const [applyingAllIn, setApplyingAllIn] = useState(false);
const allInInFlightRef = useRef(false);
+ const isMountedRef = useRef(true);
// "Repair older memories" (openhuman#6012): the backfill RPC has no other
// entry point in the app. Two steps — a dry run that only counts, then the
// real pass behind a confirmation — because the real pass embeds every
@@ -120,6 +121,13 @@ export function MemorySourcesRegistry({
tRef.current = t;
});
+ useEffect(() => {
+ isMountedRef.current = true;
+ return () => {
+ isMountedRef.current = false;
+ };
+ }, []);
+
// The toast for a run that ends while this screen is mounted. The state
// itself is the store's; a run that ends while no screen is showing still
// lands as the row's result chip on the next mount, it just goes untoasted.
@@ -195,6 +203,7 @@ export function MemorySourcesRegistry({
return null;
}),
]);
+ if (!isMountedRef.current) return;
setSources(list);
setStatuses(stats);
setPipeline(health);
@@ -207,7 +216,7 @@ export function MemorySourcesRegistry({
// finally has the field it needed.
reconcileWithStatuses(stats);
} finally {
- setLoading(false);
+ if (isMountedRef.current) setLoading(false);
}
}, []);
diff --git a/app/src/pages/FlowsPage.tsx b/app/src/pages/FlowsPage.tsx
index 18b16d0772..0e544755f6 100644
--- a/app/src/pages/FlowsPage.tsx
+++ b/app/src/pages/FlowsPage.tsx
@@ -87,6 +87,7 @@ export default function FlowsPage() {
const [busyByFlow, setBusyByFlow] = useState<Record<string, RowAction>>({});
/** Run ids started from this page that have not reported terminal yet, mapped to their start time. */
const outstandingRunsRef = useRef<Map<string, number>>(new Map());
+ const isMountedRef = useRef(true);
const setRowBusy = useCallback((flowId: string, action: RowAction | null) => {
setBusyByFlow(prev => {
if (action === null) {
@@ -126,16 +127,25 @@ export default function FlowsPage() {
setError(null);
try {
const result = await listFlows();
+ if (!isMountedRef.current) return;
setFlows(result);
log('loaded %d flows', result.length);
} catch (err) {
+ if (!isMountedRef.current) return;
log('load failed: %o', err);
setError(t('flows.page.loadError'));
} finally {
- setLoading(false);
+ if (isMountedRef.current) setLoading(false);
}
}, [t]);
+ useEffect(() => {
+ isMountedRef.current = true;
+ return () => {
+ isMountedRef.current = false;
+ };
+ }, []);
+
useEffect(() => {
void loadFlows();
}, [loadFlows]);