From b6ef5e9aab555e6ea72833d018e260eefdaacfcd Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Wed, 20 Mar 2024 11:53:29 +0100 Subject: [PATCH] Merge pull request #26516 from storybookjs/kasper/allow-empty-component-title Bug: Remove redundant component check, as we auto-generate titles from the file system (cherry picked from commit b389754b577cef15ddb19b2d87c5a650a3047ba3) --- code/lib/csf-tools/src/CsfFile.test.ts | 12 ++++++++++-- code/lib/csf-tools/src/CsfFile.ts | 8 -------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/code/lib/csf-tools/src/CsfFile.test.ts b/code/lib/csf-tools/src/CsfFile.test.ts index 7e0d223a23af..21e902cce52f 100644 --- a/code/lib/csf-tools/src/CsfFile.test.ts +++ b/code/lib/csf-tools/src/CsfFile.test.ts @@ -619,7 +619,7 @@ describe('CsfFile', () => { }); it('no metadata', () => { - expect(() => + expect( parse( dedent` export default { foo: '5' }; @@ -627,7 +627,15 @@ describe('CsfFile', () => { export const B = () => {}; ` ) - ).toThrow('CSF: missing title/component'); + ).toMatchInlineSnapshot(` + meta: + title: Default Title + stories: + - id: default-title--a + name: A + - id: default-title--b + name: B + `); }); it('dynamic titles', () => { diff --git a/code/lib/csf-tools/src/CsfFile.ts b/code/lib/csf-tools/src/CsfFile.ts index f1cce083da96..4516a293b1cc 100644 --- a/code/lib/csf-tools/src/CsfFile.ts +++ b/code/lib/csf-tools/src/CsfFile.ts @@ -478,14 +478,6 @@ export class CsfFile { throw new NoMetaError('missing default export', self._ast, self._fileName); } - if (!self._meta.title && !self._meta.component) { - throw new Error(dedent` - CSF: missing title/component ${formatLocation(self._ast, self._fileName)} - - More info: https://storybook.js.org/docs/react/writing-stories#default-export - `); - } - // default export can come at any point in the file, so we do this post processing last const entries = Object.entries(self._stories); self._meta.title = this._makeTitle(self._meta?.title as string);