Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions apps/frontend/src/renderer/hooks/useIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,18 @@ export function useIpcListeners(): void {

// Sync roadmap feature when task completes
if (status === 'done' || status === 'pr_created') {
useRoadmapStore.getState().markFeatureDoneBySpecId(taskId);
// Re-read state after mutation to get updated roadmap
// Use event's projectId (from callback param) — NOT the store's activeProjectId.
// During project switches, the store may hold a different project's roadmap.
const eventProjectId = projectId;
const rm = useRoadmapStore.getState().roadmap;
const currentProjectId = useProjectStore.getState().activeProjectId || useProjectStore.getState().selectedProjectId;
if (rm && currentProjectId) {
window.electronAPI.saveRoadmap(currentProjectId, rm).catch((err) => {
console.error('[useIpc] Failed to persist roadmap after task completion:', err);
});
if (rm && eventProjectId && rm.projectId === eventProjectId) {
useRoadmapStore.getState().markFeatureDoneBySpecId(taskId);
const updatedRm = useRoadmapStore.getState().roadmap;
if (updatedRm && updatedRm.projectId === eventProjectId) {
window.electronAPI.saveRoadmap(eventProjectId, updatedRm).catch((err) => {
console.error('[useIpc] Failed to persist roadmap after task completion:', err);
});
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion apps/frontend/src/renderer/stores/roadmap-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@ async function reconcileLinkedFeatures(projectId: string, roadmap: Roadmap): Pro

if (hasChanges) {
const updatedRoadmap = useRoadmapStore.getState().roadmap;
if (updatedRoadmap) {
// Guard: only save if the store still holds the same project's roadmap.
// A project switch during async reconciliation could replace the roadmap.
if (updatedRoadmap && updatedRoadmap.projectId === projectId) {
console.log('[Roadmap] Reconciled linked features with task states');
window.electronAPI.saveRoadmap(projectId, updatedRoadmap).catch((err) => {
console.error('[Roadmap] Failed to save reconciled roadmap:', err);
Expand All @@ -729,6 +731,9 @@ export async function loadRoadmap(projectId: string): Promise<void> {
// Always set current project ID first - this ensures event handlers
// only process events for the currently viewed project
store.setCurrentProjectId(projectId);
store.setRoadmap(null); // Clear immediately to prevent stale cross-project saves
store.setCompetitorAnalysis(null);
store.setGenerationStatus({ phase: 'idle', progress: 0, message: '' });

// Query if roadmap generation is currently running for this project
// This restores the generation status when switching back to a project
Expand Down
Loading