diff --git a/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts b/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts index b15c3a955659..ec355c02169d 100644 --- a/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts +++ b/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts @@ -63,6 +63,20 @@ describe('prepareStory', () => { expect(tags).toEqual(['component-1', 'component-2', 'story']); }); + it('component tags work if story do not have tags', () => { + const { tags } = prepareStory( + { id, name, tags: [], moduleExport }, + { + id, + title, + tags: ['component-1', 'component-2'], + }, + { render } + ); + + expect(tags).toEqual(['component-1', 'component-2', 'story']); + }); + it('sets a value even if annotations do not have tags', () => { const { tags } = prepareStory({ id, name, moduleExport }, { id, title }, { render }); diff --git a/code/lib/preview-api/src/modules/store/csf/prepareStory.ts b/code/lib/preview-api/src/modules/store/csf/prepareStory.ts index 311a4467c789..4a3b0415f0e4 100644 --- a/code/lib/preview-api/src/modules/store/csf/prepareStory.ts +++ b/code/lib/preview-api/src/modules/store/csf/prepareStory.ts @@ -145,7 +145,10 @@ function preparePartialAnnotations( // anything at render time. The assumption is that as we don't load all the stories at once, this // will have a limited cost. If this proves misguided, we can refactor it. - const tags = [...(storyAnnotations?.tags || componentAnnotations.tags || []), 'story']; + const tags = [ + ...(storyAnnotations?.tags?.length ? storyAnnotations.tags : componentAnnotations.tags || []), + 'story', + ]; const parameters: Parameters = combineParameters( projectAnnotations.parameters,