mirror of
https://github.com/OFFIS-ESC/constellation-analyzer
synced 2026-04-27 18:05:51 +00:00
Fix stale timelineStore.activeDocumentId when switching between loaded documents
switchToDocument called loadDocument which returned early when a document was already in memory, skipping loadTimeline and leaving timelineStore.activeDocumentId pointing to the previous document. Store operations like duplicateStateAsChild then looked up state IDs in the wrong document's timeline, causing "state not found". Fix by adding setActiveDocument to TimelineActions and calling it from switchToDocument so both stores always stay in sync on tab switch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4322f3cf63
commit
3c3c99f521
4 changed files with 13 additions and 0 deletions
|
|
@ -111,6 +111,10 @@ export const useTimelineStore = create<TimelineStore & TimelineActions>(
|
|||
console.log(`Timeline initialized for document ${documentId}`);
|
||||
},
|
||||
|
||||
setActiveDocument: (documentId: string) => {
|
||||
set({ activeDocumentId: documentId });
|
||||
},
|
||||
|
||||
loadTimeline: (documentId: string, timeline: Timeline) => {
|
||||
set((state) => {
|
||||
const newTimelines = new Map(state.timelines);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ vi.mock("./timelineStore", () => ({
|
|||
getState: () => ({
|
||||
timelines: new Map(),
|
||||
loadTimeline: vi.fn(),
|
||||
setActiveDocument: vi.fn(),
|
||||
clearTimeline: vi.fn(),
|
||||
}),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -600,6 +600,11 @@ export const useWorkspaceStore = create<Workspace & WorkspaceActions>((set, get)
|
|||
activeDocumentId: documentId,
|
||||
};
|
||||
});
|
||||
|
||||
// Always sync timelineStore.activeDocumentId — loadDocument returns early
|
||||
// when the document is already in memory, so loadTimeline is never called
|
||||
// and timelineStore.activeDocumentId would remain stale.
|
||||
useTimelineStore.getState().setActiveDocument(documentId);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ export interface TimelineActions {
|
|||
// Load timeline from document
|
||||
loadTimeline: (documentId: string, timeline: Timeline) => void;
|
||||
|
||||
// Set active document without reloading timeline data (for switching between already-loaded documents)
|
||||
setActiveDocument: (documentId: string) => void;
|
||||
|
||||
// Create new state
|
||||
createState: (label: string, description?: string, cloneFromCurrent?: boolean) => StateId;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue