Skip to content

Commit

Permalink
Merge branch 'next' into 22163_logEventFalseyFix
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Apr 29, 2024
2 parents 6b509a5 + f6ecc28 commit bbafa40
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
15 changes: 15 additions & 0 deletions code/builders/builder-vite/src/assetsInclude.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { InlineConfig as ViteInlineConfig } from 'vite';

export function getAssetsInclude(config: ViteInlineConfig, newPath: string[]): (string | RegExp)[] {
const { assetsInclude } = config;

if (!assetsInclude) {
return newPath;
}

if (Array.isArray(assetsInclude)) {
return [...assetsInclude, ...newPath];
} else {
return [assetsInclude, ...newPath];
}
}
3 changes: 2 additions & 1 deletion code/builders/builder-vite/src/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Options } from '@storybook/types';
import { commonConfig } from './vite-config';
import { getOptimizeDeps } from './optimizeDeps';
import { sanitizeEnvVars } from './envs';
import { getAssetsInclude } from './assetsInclude';

export async function createViteServer(options: Options, devServer: Server) {
const { presets } = options;
Expand All @@ -12,7 +13,7 @@ export async function createViteServer(options: Options, devServer: Server) {
const config = {
...commonCfg,
// Needed in Vite 5: https://github.com/storybookjs/storybook/issues/25256
assetsInclude: ['/sb-preview/**'],
assetsInclude: getAssetsInclude(commonCfg, ['/sb-preview/**']),
// Set up dev server
server: {
middlewareMode: true,
Expand Down
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 bbafa40

Please sign in to comment.