Skip to content

Commit

Permalink
Merge pull request #26949 from storybookjs/yann/investigate-safari-fl…
Browse files Browse the repository at this point in the history
…akiness

Core: Fix filters not being applied in WebKit
  • Loading branch information
JReinhold authored Apr 26, 2024
2 parents 34f0c20 + cfe6e11 commit 7e1ee32
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions code/lib/manager-api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,20 @@ export const init: ModuleFn<SubAPI, SubState> = ({
}
},
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);
});
},
};

Expand Down Expand Up @@ -879,6 +882,7 @@ export const init: ModuleFn<SubAPI, SubState> = ({
},
init: async () => {
provider.channel?.on(STORY_INDEX_INVALIDATED, () => api.fetchIndex());

await api.fetchIndex();
},
};
Expand Down

0 comments on commit 7e1ee32

Please sign in to comment.