diff --git a/code/lib/manager-api/src/modules/stories.ts b/code/lib/manager-api/src/modules/stories.ts index 78c3307f179f..19ea80ce41f4 100644 --- a/code/lib/manager-api/src/modules/stories.ts +++ b/code/lib/manager-api/src/modules/stories.ts @@ -648,17 +648,20 @@ export const init: ModuleFn = ({ } }, experimental_setFilter: async (id, filterFunction) => { - const { internal_index: index } = store.getState(); await store.setState({ filters: { ...store.getState().filters, [id]: filterFunction } }); - if (index) { - await api.setIndex(index); + const { internal_index: index } = store.getState(); - const refs = await fullAPI.getRefs(); - Object.entries(refs).forEach(([refId, { internal_index, ...ref }]) => { - fullAPI.setRef(refId, { ...ref, storyIndex: internal_index }, true); - }); + if (!index) { + return; } + // apply new filters by setting the index again + await api.setIndex(index); + + const refs = await fullAPI.getRefs(); + Object.entries(refs).forEach(([refId, { internal_index, ...ref }]) => { + fullAPI.setRef(refId, { ...ref, storyIndex: internal_index }, true); + }); }, }; @@ -879,6 +882,7 @@ export const init: ModuleFn = ({ }, init: async () => { provider.channel?.on(STORY_INDEX_INVALIDATED, () => api.fetchIndex()); + await api.fetchIndex(); }, };