Skip to content

Commit c523857

Browse files
committed
fix: workspace selection race, unhandled delete rejections
- RunnerPage: store continuation workspace in ref to survive location.state clearing; remove stale location.state read from apps initializer - RunsHistoryPage: catch deleteRun failures to prevent optimistic UI update - HistoryPage: catch clearHistory/deleteHistoryEntry failures gracefully
1 parent 53be2d8 commit c523857

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

client/src/pages/HistoryPage.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ export function HistoryPage() {
3535
}, [loadData]);
3636

3737
const handleClear = async () => {
38-
await api.clearHistory();
38+
const result = await api.clearHistory().catch(() => null);
39+
if (result === null) return;
3940
setConfirmingClear(false);
4041
loadData();
4142
};
4243

4344
const handleDelete = async (id, e) => {
4445
e.stopPropagation();
45-
await api.deleteHistoryEntry(id);
46+
const result = await api.deleteHistoryEntry(id).catch(() => null);
47+
if (result === null) return;
4648
setHistory(prev => prev.filter(entry => entry.id !== id));
4749
if (expandedId === id) setExpandedId(null);
4850
};

client/src/pages/RunnerPage.jsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ export function RunnerPage() {
2828
const [continueContext, setContinueContext] = useState(null);
2929
const fileInputRef = useRef(null);
3030
const outputRef = useRef(null);
31+
const continueWorkspaceRef = useRef(location.state?.continueFrom?.workspacePath ?? null);
3132

3233
// Get the selected app's repoPath
3334
const selectedApp = apps.find(a => a.id === selectedAppId);
3435
const workspacePath = selectedApp?.repoPath || '';
3536

36-
// Handle continuation context from navigation
37+
// Handle continuation context from navigation — store continueFrom and clear location state once
3738
useEffect(() => {
3839
const continueFrom = location.state?.continueFrom;
3940
if (continueFrom) {
@@ -45,17 +46,10 @@ export function RunnerPage() {
4546
if (continueFrom.model) {
4647
setSelectedModel(continueFrom.model);
4748
}
48-
// Set workspace from previous run if available
49-
if (continueFrom.workspacePath) {
50-
const app = apps.find(a => a.repoPath === continueFrom.workspacePath);
51-
if (app) {
52-
setSelectedAppId(app.id);
53-
}
54-
}
5549
// Clear location state to prevent re-triggering on refresh
5650
navigate(location.pathname, { replace: true, state: null });
5751
}
58-
}, [location.state, apps]);
52+
}, [location.state, navigate]);
5953

6054
useEffect(() => {
6155
Promise.all([
@@ -66,12 +60,11 @@ export function RunnerPage() {
6660
// Filter out PortOS Autofixer (it's part of PortOS project)
6761
const filteredApps = appsData.filter(a => a.id !== 'portos-autofixer');
6862
setApps(filteredApps);
69-
// Set workspace: prefer continuation context, then PortOS, then first app
63+
// Set workspace: prefer continuation context (stored in ref), then PortOS, then first app
7064
setSelectedAppId(prev => {
7165
if (prev) return prev;
72-
const continueWorkspacePath = location.state?.continueFrom?.workspacePath;
73-
if (continueWorkspacePath) {
74-
const continueApp = filteredApps.find(a => a.repoPath === continueWorkspacePath);
66+
if (continueWorkspaceRef.current) {
67+
const continueApp = filteredApps.find(a => a.repoPath === continueWorkspaceRef.current);
7568
if (continueApp) return continueApp.id;
7669
}
7770
const portosApp = filteredApps.find(a => a.name === 'PortOS');

client/src/pages/RunsHistoryPage.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export function RunsHistoryPage() {
4141

4242
const handleDelete = async (id, e) => {
4343
e.stopPropagation();
44-
await api.deleteRun(id);
44+
const deleted = await api.deleteRun(id).catch(() => null);
45+
if (!deleted && deleted !== undefined) return;
4546
setRuns(prev => prev.filter(run => run.id !== id));
4647
if (expandedId === id) setExpandedId(null);
4748
};

0 commit comments

Comments
 (0)