diff --git a/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts b/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts index 6c85760cbd4e..24e286b3b909 100644 --- a/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts +++ b/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts @@ -77,6 +77,25 @@ describe('composeStory', () => { expect(composedStory.parameters.fromAnnotations.asDefaultImport).toEqual(true); }); + it('should compose project annotations when used in named and default exports from the same module', () => { + setProjectAnnotations([ + { + initialGlobals: { namedExportAnnotation: true }, + default: { + parameters: { defaultExportAnnotation: true }, + }, + }, + ]); + + const Story: Story = { + render: () => {}, + }; + + const composedStory = composeStory(Story, meta); + expect(composedStory.parameters.defaultExportAnnotation).toEqual(true); + expect(composedStory.globals.namedExportAnnotation).toEqual(true); + }); + it('should return story with composed annotations from story, meta and project', () => { const decoratorFromProjectAnnotations = vi.fn((StoryFn) => StoryFn()); const decoratorFromStoryAnnotations = vi.fn((StoryFn) => StoryFn()); diff --git a/code/core/src/preview-api/modules/store/csf/portable-stories.ts b/code/core/src/preview-api/modules/store/csf/portable-stories.ts index b9efd7da9792..22b449bd98f0 100644 --- a/code/core/src/preview-api/modules/store/csf/portable-stories.ts +++ b/code/core/src/preview-api/modules/store/csf/portable-stories.ts @@ -61,11 +61,8 @@ function extractAnnotation( // import * as annotations from '.storybook/preview' // import annotations from '.storybook/preview' // in both cases: 1 - the file has a default export; 2 - named exports only - // support imports such as - // import * as annotations from '.storybook/preview' - // import annotations from '.storybook/preview' - // in both cases: 1 - the file has a default export; 2 - named exports only - return 'default' in annotation ? annotation.default : annotation; + // also support when the file has both annotations coming from default and named exports + return composeConfigs([annotation]); } export function setProjectAnnotations(