diff --git a/code/lib/manager-api/src/modules/stories.ts b/code/lib/manager-api/src/modules/stories.ts index 07d6fb702d3..795f9460b10 100644 --- a/code/lib/manager-api/src/modules/stories.ts +++ b/code/lib/manager-api/src/modules/stories.ts @@ -412,6 +412,10 @@ export const init: ModuleFn = ({ if (!entry) throw new Error(`Unknown id or title: '${titleOrId}'`); + store.setState({ + settings: { ...store.getState().settings, lastTrackedStoryId: entry.id }, + }); + // We want to navigate to the first ancestor entry that is a leaf const leafEntry = api.findLeafEntry(hash, entry.id); const fullId = leafEntry.refId ? `${leafEntry.refId}_${leafEntry.id}` : leafEntry.id; diff --git a/code/lib/manager-api/src/tests/stories.test.ts b/code/lib/manager-api/src/tests/stories.test.ts index a6617bce9f4..76213e10be2 100644 --- a/code/lib/manager-api/src/tests/stories.test.ts +++ b/code/lib/manager-api/src/tests/stories.test.ts @@ -899,6 +899,16 @@ describe('stories API', () => { api.selectStory('intro'); expect(navigate).toHaveBeenCalledWith('/docs/intro--docs'); }); + it('updates lastTrackedStoryId', () => { + const initialState = { path: '/story/a--1', storyId: 'a--1', viewMode: 'story' }; + const moduleArgs = createMockModuleArgs({ initialState }); + const { api } = initStories(moduleArgs as unknown as ModuleArgs); + const { store } = moduleArgs; + + api.setIndex({ v: 4, entries: navigationEntries }); + api.selectStory('a--1'); + expect(store.getState().settings.lastTrackedStoryId).toBe('a--1'); + }); describe('deprecated api', () => { it('allows navigating to a combination of title + name', () => { const initialState = { path: '/story/a--1', storyId: 'a--1', viewMode: 'story' };