From 566ce343d00dfbf3c7db549bb3788b1f764203f7 Mon Sep 17 00:00:00 2001 From: Obvious Date: Fri, 9 Oct 2026 13:48:32 +0000 Subject: [PATCH 1/8] refactor(csf): remove deprecated CSF and manager type aliases Remove the six deprecated surfaces from the storybook package and migrate every in-repo consumer to the supported replacements: - StoryKind -> ComponentTitle - StoryIdentifier.kind / .story -> title / name (members deleted, along with the back-compat writes in prepareStory, StoryRender, and the sanitizeStoryContextUpdate protected keys) - AnyFramework -> Renderer - StoryContextForLoaders -> StoryContext (LoaderFunction signature) - PlayFunctionContext -> StoryContext (PlayFunction signature) - StoriesHash -> IndexHash (manager-api re-export and 7 manager sites) Also strips the legacy manager wire-format accommodations those fields fed: the SELECT_STORY kind/story fallbacks, the setStories transform's kindParameters lookup and kind/story index migrations, and the composed refs defaultStoryMapper kind normalization. Addon-links migrates type-only; its data-sb-kind / data-sb-story runtime contract is intact. MIGRATION.md documents the alias -> replacement pairs. --- MIGRATION.md | 18 +++++ .../components/VisionSimulator.stories.tsx | 2 +- .../src/blocks/blocks/ArgTypes.stories.tsx | 4 +- .../src/blocks/blocks/Controls.stories.tsx | 4 +- .../src/blocks/components/Story.stories.tsx | 4 +- .../links/src/react/components/link.tsx | 4 +- code/addons/links/src/utils.ts | 4 +- code/core/src/csf/story.ts | 35 +++------ code/core/src/manager-api/lib/stories.test.ts | 57 --------------- code/core/src/manager-api/lib/stories.ts | 73 +------------------ code/core/src/manager-api/modules/refs.ts | 32 +------- code/core/src/manager-api/modules/stories.ts | 9 +-- code/core/src/manager-api/root.tsx | 2 - .../src/manager-api/tests/stories.test.ts | 73 ++++++++++++++++++- .../sidebar/SearchResults.stories.tsx | 4 +- .../components/sidebar/StatusContext.tsx | 4 +- .../src/manager/components/sidebar/Tree.tsx | 10 +-- .../src/manager/components/sidebar/types.ts | 14 +++- .../manager/components/sidebar/useExpanded.ts | 8 +- code/core/src/manager/container/Preview.tsx | 4 +- code/core/src/manager/container/Sidebar.tsx | 4 +- .../modules/preview-web/render/StoryRender.ts | 6 +- .../modules/store/csf/prepareStory.test.ts | 1 - .../modules/store/csf/prepareStory.ts | 5 +- .../modules/store/decorators.test.ts | 17 +++-- .../preview-api/modules/store/decorators.ts | 2 - code/core/src/types/modules/addons.ts | 3 - code/core/src/types/modules/channelApi.ts | 2 - code/core/src/types/modules/csf.ts | 3 - .../template/stories/argMapping.stories.ts | 6 +- .../core/template/stories/argTypes.stories.ts | 12 +-- code/core/template/stories/args.stories.ts | 8 +- .../template/stories/autotitle.stories.ts | 4 +- .../stories/component-play.stories.ts | 4 +- .../template/stories/decorators.stories.ts | 5 +- code/core/template/stories/globals.stories.ts | 10 +-- code/core/template/stories/indexer.stories.ts | 6 +- code/core/template/stories/names.stories.ts | 6 +- .../template/stories/parameters.stories.ts | 4 +- .../template/stories/rendering.stories.ts | 6 +- .../template/stories/shortcuts.stories.ts | 4 +- .../core/template/stories/tags-add.stories.ts | 4 +- .../template/stories/tags-config.stories.ts | 4 +- .../template/stories/tags-remove.stories.ts | 4 +- code/core/template/stories/title.stories.ts | 4 +- .../ember/src/client/preview/render.ts | 4 +- code/renderers/html/src/render.ts | 4 +- code/renderers/web-components/src/render.ts | 4 +- 48 files changed, 204 insertions(+), 307 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index b2aa8015cd82..96635bf024f8 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -807,6 +807,24 @@ export const Primary: Story = { Decorators and `render` functions keep receiving `argTypes`, because renderers rely on them while rendering. Their context type is the new `StoryContextForRender`; the `StoryContext` type no longer declares `argTypes`. Custom decorator or render helpers that annotate their context parameter as `StoryContext` and read `argTypes` should switch to `StoryContextForRender`. +### Deprecated CSF and manager type aliases removed + +Six deprecated type aliases from earlier Storybook versions are removed. If your code imports any of them from `storybook` (via `storybook/internal/csf`, `storybook/internal/types`, or `storybook/manager-api`), switch to the supported replacement: + +| Deprecated | Replacement | +| ----------------------- | ----------------------- | +| `StoryKind` | `ComponentTitle` | +| `StoryIdentifier.kind` | `StoryIdentifier.title` | +| `StoryIdentifier.story` | `StoryIdentifier.name` | +| `AnyFramework` | `Renderer` | +| `StoryContextForLoaders` | `StoryContext` | +| `PlayFunctionContext` | `StoryContext` | +| `StoriesHash` | `IndexHash` | + +Story context objects passed to loaders and play functions no longer carry the deprecated `kind` and `story` keys; read `title` and `name` instead. The same applies to the context passed to decorators and `render` functions: custom helpers that read `context.kind` or `context.story` must switch to `context.title` and `context.name`. + +The manager no longer accepts the pre-Storybook 3 wire format either: `SELECT_STORY` payloads are resolved from `storyId` or `title`/`name` only, and composed refs must publish a story index (`stories.json`) instead of a legacy `setStories` payload. + ### `docgenServer` is stable and enabled by default The `experimentalDocgenServer` feature is now `docgenServer`, and Storybook no longer reads the old name. diff --git a/code/addons/a11y/src/components/VisionSimulator.stories.tsx b/code/addons/a11y/src/components/VisionSimulator.stories.tsx index ec3972219667..59388551cb3c 100644 --- a/code/addons/a11y/src/components/VisionSimulator.stories.tsx +++ b/code/addons/a11y/src/components/VisionSimulator.stories.tsx @@ -1,4 +1,4 @@ -import type { PlayFunction, PlayFunctionContext } from 'storybook/internal/types'; +import type { PlayFunction } from 'storybook/internal/types'; import { ManagerContext } from 'storybook/manager-api'; import { expect, fn, screen } from 'storybook/test'; diff --git a/code/addons/docs/src/blocks/blocks/ArgTypes.stories.tsx b/code/addons/docs/src/blocks/blocks/ArgTypes.stories.tsx index ba6e53203f60..12a4bb0cde0f 100644 --- a/code/addons/docs/src/blocks/blocks/ArgTypes.stories.tsx +++ b/code/addons/docs/src/blocks/blocks/ArgTypes.stories.tsx @@ -1,5 +1,5 @@ /** Custom docs page: {@link ./ArgTypes.mdx} (attached via ``). */ -import type { PlayFunctionContext } from 'storybook/internal/csf'; +import type { StoryContext } from 'storybook/internal/csf'; import type { Meta, StoryObj } from '@storybook/react-vite'; @@ -133,7 +133,7 @@ const DOCGEN_TIMEOUT = { timeout: 5000 }; const findSubcomponentTabs = async ( canvas: Parameters>[0]['canvas'], - step: PlayFunctionContext['step'] + step: StoryContext['step'] ) => { let subcomponentATab: HTMLElement | null = null; let subcomponentBTab: HTMLElement | null = null; diff --git a/code/addons/docs/src/blocks/blocks/Controls.stories.tsx b/code/addons/docs/src/blocks/blocks/Controls.stories.tsx index 6f469887fa84..9dcecaa027db 100644 --- a/code/addons/docs/src/blocks/blocks/Controls.stories.tsx +++ b/code/addons/docs/src/blocks/blocks/Controls.stories.tsx @@ -1,7 +1,7 @@ /** Custom docs page: {@link ./Controls.mdx} (attached via ``). */ import React from 'react'; -import type { PlayFunctionContext } from 'storybook/internal/csf'; +import type { StoryContext } from 'storybook/internal/csf'; import type { Meta, StoryObj } from '@storybook/react-vite'; @@ -103,7 +103,7 @@ const DOCGEN_TIMEOUT = { timeout: 5000 }; const findSubcomponentTabs = async ( canvas: ReturnType, - step: PlayFunctionContext['step'] + step: StoryContext['step'] ) => { let subcomponentATab: HTMLElement | null = null; let subcomponentBTab: HTMLElement | null = null; diff --git a/code/addons/docs/src/blocks/components/Story.stories.tsx b/code/addons/docs/src/blocks/components/Story.stories.tsx index d6e15cc702fa..a4b5d8430585 100644 --- a/code/addons/docs/src/blocks/components/Story.stories.tsx +++ b/code/addons/docs/src/blocks/components/Story.stories.tsx @@ -6,7 +6,7 @@ import { STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, } from 'storybook/internal/core-events'; -import type { PlayFunctionContext } from 'storybook/internal/csf'; +import type { StoryContext } from 'storybook/internal/csf'; import type { ModuleExport, WebRenderer } from 'storybook/internal/types'; import type { Meta, ReactRenderer, StoryObj } from '@storybook/react-vite'; @@ -97,7 +97,7 @@ export const ForceInitialArgs = { chromatic: { disableSnapshot: true }, }, // test that it ignores updated args by emitting an arg update and assert that it isn't reflected in the DOM - play: async ({ args, canvasElement, loaded }: PlayFunctionContext) => { + play: async ({ args, canvasElement, loaded }: StoryContext) => { const docsContext = loaded.docsContext as DocsContextProps; const resolved = docsContext.resolveOf(args.storyExport, ['story']); diff --git a/code/addons/links/src/react/components/link.tsx b/code/addons/links/src/react/components/link.tsx index 9e3930c3b30c..837b720f60c3 100644 --- a/code/addons/links/src/react/components/link.tsx +++ b/code/addons/links/src/react/components/link.tsx @@ -1,7 +1,7 @@ import type { MouseEvent, ReactNode } from 'react'; import React, { PureComponent } from 'react'; -import type { ComponentTitle, StoryKind, StoryName } from 'storybook/internal/types'; +import type { ComponentTitle, StoryName } from 'storybook/internal/types'; import { hrefTo, navigate } from '../../utils.ts'; @@ -22,7 +22,7 @@ const cancelled = (e: MouseEvent, cb = (_e: any) => {}) => { }; interface Props { - kind?: StoryKind; + kind?: ComponentTitle; title?: ComponentTitle; story?: StoryName; name?: StoryName; diff --git a/code/addons/links/src/utils.ts b/code/addons/links/src/utils.ts index aa8b2eadb602..e3836cc99364 100644 --- a/code/addons/links/src/utils.ts +++ b/code/addons/links/src/utils.ts @@ -1,6 +1,6 @@ import { SELECT_STORY, STORY_CHANGED } from 'storybook/internal/core-events'; import { toId } from 'storybook/internal/csf'; -import type { ComponentTitle, StoryId, StoryKind, StoryName } from 'storybook/internal/types'; +import type { ComponentTitle, StoryId, StoryName } from 'storybook/internal/types'; import { global } from '@storybook/global'; @@ -14,7 +14,7 @@ interface ParamsId { storyId: StoryId; } interface ParamsCombo { - kind?: StoryKind; + kind?: ComponentTitle; title?: ComponentTitle; story?: StoryName; name?: StoryName; diff --git a/code/core/src/csf/story.ts b/code/core/src/csf/story.ts index 76df3b97f908..6026edefcdf3 100644 --- a/code/core/src/csf/story.ts +++ b/code/core/src/csf/story.ts @@ -13,21 +13,14 @@ export type ComponentId = string; export type ComponentTitle = string; export type StoryName = string; -/** @deprecated */ -export type StoryKind = ComponentTitle; - export type Tag = string; export interface StoryIdentifier { componentId: ComponentId; title: ComponentTitle; - /** @deprecated */ - kind: ComponentTitle; id: StoryId; name: StoryName; - /** @deprecated */ - story: StoryName; tags: Tag[]; } @@ -130,7 +123,10 @@ export interface InputType { /** @see https://storybook.js.org/docs/api/arg-types#tablecategory */ category?: string; /** @see https://storybook.js.org/docs/api/arg-types#tabledefaultvalue */ - defaultValue?: { summary?: string | undefined; detail?: string | undefined }; + defaultValue?: { + summary?: string | undefined; + detail?: string | undefined; + }; /** @see https://storybook.js.org/docs/api/arg-types#tabledisable */ disable?: boolean; /** @see https://storybook.js.org/docs/api/arg-types#tablesubcategory */ @@ -163,7 +159,9 @@ export interface StrictArgs { /** @see https://storybook.js.org/docs/api/arg-types#argtypes */ export type ArgTypes = { [name in keyof TArgs]: InputType }; -export type StrictArgTypes = { [name in keyof TArgs]: StrictInputType }; +export type StrictArgTypes = { + [name in keyof TArgs]: StrictInputType; +}; export interface Globals { [name: string]: any; @@ -217,9 +215,6 @@ export interface Renderer extends AddonTypes { csf4: boolean; } -/** @deprecated - Use `Renderer` */ -export type AnyFramework = Renderer; - export interface StoryContextForEnhancers< TRenderer extends Renderer = Renderer, TArgs = Args, @@ -251,7 +246,7 @@ export interface StoryContextUpdate { export type ViewMode = 'story' | 'docs'; export type LoaderFunction = ( - context: StoryContextForLoaders + context: StoryContext ) => Promise | void> | Record | void; type Awaitable = T | PromiseLike; @@ -306,18 +301,6 @@ export interface StoryContextForRender< argTypes: StrictArgTypes; } -/** @deprecated Use {@link StoryContext} instead. */ -export interface StoryContextForLoaders< - TRenderer extends Renderer = Renderer, - TArgs = Args, -> extends StoryContext {} - -/** @deprecated Use {@link StoryContext} instead. */ -export interface PlayFunctionContext< - TRenderer extends Renderer = Renderer, - TArgs = Args, -> extends StoryContext {} - export type StepLabel = string; export type StepFunction = ( @@ -326,7 +309,7 @@ export type StepFunction = ) => Promise | void; export type PlayFunction = ( - context: PlayFunctionContext + context: StoryContext ) => Promise | void; export type TestFunction = ( diff --git a/code/core/src/manager-api/lib/stories.test.ts b/code/core/src/manager-api/lib/stories.test.ts index a4a2916f368b..047b29a6bf86 100644 --- a/code/core/src/manager-api/lib/stories.test.ts +++ b/code/core/src/manager-api/lib/stories.test.ts @@ -3,7 +3,6 @@ import { describe, expect, it } from 'vitest'; import { type API_PreparedStoryIndex, type StatusesByStoryIdAndTypeId, - type StoryIndexV2, type StoryIndexV3, } from 'storybook/internal/types'; @@ -11,18 +10,10 @@ import type { State } from '../root.tsx'; import { mockEntries } from '../tests/mockStoriesEntries.ts'; import { transformStoryIndexToStoriesHash, - transformStoryIndexV2toV3, transformStoryIndexV3toV4, transformStoryIndexV4toV5, } from './stories.ts'; -const baseV2: StoryIndexV2['stories'][0] = { - id: '1', - story: '', - kind: '', - parameters: {}, -}; - const baseV3: StoryIndexV3['stories'][0] = { id: '1', title: '', @@ -33,54 +24,6 @@ const baseV3: StoryIndexV3['stories'][0] = { importPath: '', }; -describe('transformStoryIndexV2toV3', () => { - it('transforms a StoryIndexV2 to a StoryIndexV3 correctly', () => { - const indexV2: StoryIndexV2 = { - v: 2, - stories: { - '1': { - ...baseV2, - id: '1', - kind: 'story', - story: 'Story 1', - }, - '2': { - ...baseV2, - id: '2', - kind: 'blog', - story: 'Blog 1', - }, - }, - }; - - expect(transformStoryIndexV2toV3(indexV2)).toMatchInlineSnapshot(` - { - "stories": { - "1": { - "id": "1", - "importPath": "", - "kind": "story", - "name": "Story 1", - "parameters": {}, - "story": "Story 1", - "title": "story", - }, - "2": { - "id": "2", - "importPath": "", - "kind": "blog", - "name": "Blog 1", - "parameters": {}, - "story": "Blog 1", - "title": "blog", - }, - }, - "v": 3, - } - `); - }); -}); - describe('transformStoryIndexV3toV4', () => { it('transforms a StoryIndexV3 to an API_PreparedStoryIndex correctly', () => { const indexV3: StoryIndexV3 = { diff --git a/code/core/src/manager-api/lib/stories.ts b/code/core/src/manager-api/lib/stories.ts index 0c3cca7d2406..eb22188d1ee2 100644 --- a/code/core/src/manager-api/lib/stories.ts +++ b/code/core/src/manager-api/lib/stories.ts @@ -17,7 +17,6 @@ import type { SetStoriesStoryData, StatusesByStoryIdAndTypeId, StoryId, - StoryIndexV2, StoryIndexV3, } from 'storybook/internal/types'; @@ -35,81 +34,14 @@ const TITLE_PATH_SEPARATOR = /\s*\/\s*/; export const denormalizeStoryParameters = ({ globalParameters, - kindParameters, stories, }: SetStoriesPayload): SetStoriesStoryData => { return mapValues(stories, (storyData) => ({ ...storyData, - parameters: combineParameters( - globalParameters, - kindParameters[storyData.kind], - storyData.parameters as unknown as Parameters - ), + parameters: combineParameters(globalParameters, storyData.parameters as unknown as Parameters), })) as SetStoriesStoryData; }; -export const transformSetStoriesStoryDataToPreparedStoryIndex = ( - stories: SetStoriesStoryData -): API_PreparedStoryIndex => { - const entries: API_PreparedStoryIndex['entries'] = Object.entries(stories).reduce( - (acc, [id, story]) => { - if (!story) { - return acc; - } - - const { docsOnly, fileName, ...parameters } = story.parameters; - const base = { - title: story.kind, - id, - name: story.name, - importPath: fileName, - }; - if (docsOnly) { - acc[id] = { - type: 'docs', - tags: ['stories-mdx'], - storiesImports: [], - ...base, - }; - } else { - const { argTypes, args, initialArgs } = story; - acc[id] = { - type: 'story', - subtype: 'story', - ...base, - parameters, - argTypes, - args, - initialArgs, - }; - } - return acc; - }, - {} as API_PreparedStoryIndex['entries'] - ); - - return { v: 5, entries }; -}; - -export const transformStoryIndexV2toV3 = (index: StoryIndexV2): StoryIndexV3 => { - return { - v: 3, - stories: Object.values(index.stories).reduce( - (acc, entry) => { - acc[entry.id] = { - ...entry, - title: entry.kind, - name: entry.name || entry.story, - importPath: entry.parameters.fileName || '', - }; - - return acc; - }, - {} as StoryIndexV3['stories'] - ), - }; -}; - export const transformStoryIndexV3toV4 = (index: StoryIndexV3): API_PreparedStoryIndex => { const countByTitle = countBy(Object.values(index.stories), (item) => item.title); return { @@ -175,7 +107,7 @@ type ToStoriesHashOptions = { }; export const transformStoryIndexToStoriesHash = ( - input: API_PreparedStoryIndex | StoryIndexV2 | StoryIndexV3, + input: API_PreparedStoryIndex | StoryIndexV3, { provider, docsOptions, filters, allStatuses, statusFilterKey }: ToStoriesHashOptions ): API_IndexHash => { if (!input.v) { @@ -183,7 +115,6 @@ export const transformStoryIndexToStoriesHash = ( } let index = input; - index = index.v === 2 ? transformStoryIndexV2toV3(index as any) : index; index = index.v === 3 ? transformStoryIndexV3toV4(index as any) : index; index = index.v === 4 ? transformStoryIndexV4toV5(index as any) : index; index = index as API_PreparedStoryIndex; diff --git a/code/core/src/manager-api/modules/refs.ts b/code/core/src/manager-api/modules/refs.ts index a62acbb134e2..afc509b4ee67 100644 --- a/code/core/src/manager-api/modules/refs.ts +++ b/code/core/src/manager-api/modules/refs.ts @@ -5,8 +5,6 @@ import type { API_RefStoryRuntimeData, API_Refs, API_SetRefData, - API_StoryMapper, - SetStoriesStoryData, StoryIndex, } from 'storybook/internal/types'; @@ -14,10 +12,7 @@ import { global } from '@storybook/global'; import { dedent } from 'ts-dedent'; -import { - transformSetStoriesStoryDataToPreparedStoryIndex, - transformStoryIndexToStoriesHash, -} from '../lib/stories.ts'; +import { transformStoryIndexToStoriesHash } from '../lib/stories.ts'; import type { ModuleFn } from '../lib/types.tsx'; const { location, fetch } = global; @@ -94,10 +89,6 @@ export const getSourceType = (source: string, refId?: string) => { return [null, null]; }; -export const defaultStoryMapper: API_StoryMapper = (b: any, a: any) => { - return { ...a, kind: a.kind.replace('|', '/') }; -}; - const addRefIds = (input: API_IndexHash, ref: API_ComposedRef): API_IndexHash => { return Object.entries(input).reduce((acc, [id, item]) => { return { ...acc, [id]: { ...item!, refId: ref.id } }; @@ -185,20 +176,6 @@ const parseUrl = (url: string): UrlParseResult => { }; }; -const map = ( - input: SetStoriesStoryData, - ref: API_ComposedRef, - options: { storyMapper?: API_StoryMapper } -): SetStoriesStoryData => { - const { storyMapper } = options; - if (storyMapper) { - return Object.entries(input).reduce((acc, [id, item]) => { - return { ...acc, [id]: storyMapper(ref, item) }; - }, {} as SetStoriesStoryData); - } - return input; -}; - export const init: ModuleFn = ( { store, provider, singleStory, docsOptions = {} }, { runCheck = true } = {} @@ -333,15 +310,10 @@ export const init: ModuleFn = ( let index: API_IndexHash | undefined; let filteredIndex: API_IndexHash | undefined; const { filters } = store.getState(); - const { storyMapper = defaultStoryMapper } = provider.getConfig(); const ref = api.getRefs()[id]; if (storyIndex || setStoriesData) { - internal_index = setStoriesData - ? transformSetStoriesStoryDataToPreparedStoryIndex( - map(setStoriesData, ref, { storyMapper }) - ) - : storyIndex; + internal_index = storyIndex; // @ts-expect-error (could be undefined) filteredIndex = transformStoryIndexToStoriesHash(storyIndex, { diff --git a/code/core/src/manager-api/modules/stories.ts b/code/core/src/manager-api/modules/stories.ts index 4c60f9052f28..6317827d4061 100644 --- a/code/core/src/manager-api/modules/stories.ts +++ b/code/core/src/manager-api/modules/stories.ts @@ -42,7 +42,6 @@ import type { StatusValue, StoryId, StoryIndex, - StoryKind, StoryName, StoryPreparedPayload, Tag, @@ -1263,16 +1262,12 @@ export const init: ModuleFn = ({ function handler( this: any, { - kind, - title = kind, - story, - name = story, + title, + name, storyId, ...rest }: { - kind?: StoryKind; title?: ComponentTitle; - story?: StoryName; name?: StoryName; storyId: string; viewMode: API_ViewMode; diff --git a/code/core/src/manager-api/root.tsx b/code/core/src/manager-api/root.tsx index 3806fb981f65..3b7b45951950 100644 --- a/code/core/src/manager-api/root.tsx +++ b/code/core/src/manager-api/root.tsx @@ -334,8 +334,6 @@ export function useStorybookApi(): API { } export type { - /** @deprecated Now IndexHash */ - API_IndexHash as StoriesHash, API_IndexHash as IndexHash, API_RootEntry as RootEntry, API_GroupEntry as GroupEntry, diff --git a/code/core/src/manager-api/tests/stories.test.ts b/code/core/src/manager-api/tests/stories.test.ts index 9e8b7b73ab2b..cee213b3592f 100644 --- a/code/core/src/manager-api/tests/stories.test.ts +++ b/code/core/src/manager-api/tests/stories.test.ts @@ -6,6 +6,7 @@ import { CURRENT_STORY_WAS_SET, DOCS_PREPARED, RESET_STORY_ARGS, + SELECT_STORY, SET_CONFIG, SET_FILTER, SET_INDEX, @@ -1428,7 +1429,10 @@ describe('stories API', () => { { id: 'ref', setStoriesData: { - 'a--1': { kind: 'a', parameters: { global: 'global', kind: 'kind', story: 'story' } }, + 'a--1': { + kind: 'a', + parameters: { global: 'global', story: 'story' }, + }, }, }, true @@ -1466,6 +1470,73 @@ describe('stories API', () => { ); }); }); + describe('SELECT_STORY event', () => { + it('resolves the story from title and name', () => { + const fullAPI = { + findRef: vi.fn(), + setRef: vi.fn(), + selectStory: vi.fn(), + }; + const moduleArgs = createMockModuleArgs({ fullAPI }); + initStories(moduleArgs as unknown as ModuleArgs); + const { provider } = moduleArgs; + + getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); + provider.channel.emit(SELECT_STORY, { + title: 'a', + name: '1', + viewMode: 'story', + }); + + expect(fullAPI.selectStory).toHaveBeenCalledWith('a', '1', { + viewMode: 'story', + }); + }); + + it('resolves the story from storyId when provided', () => { + const fullAPI = { + findRef: vi.fn(), + setRef: vi.fn(), + selectStory: vi.fn(), + }; + const moduleArgs = createMockModuleArgs({ fullAPI }); + initStories(moduleArgs as unknown as ModuleArgs); + const { provider } = moduleArgs; + + getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); + provider.channel.emit(SELECT_STORY, { + storyId: 'a--1', + viewMode: 'story', + }); + + expect(fullAPI.selectStory).toHaveBeenCalledWith('a--1', undefined, { + viewMode: 'story', + }); + }); + + it('does not fall back to the legacy kind/story payload fields', () => { + const fullAPI = { + findRef: vi.fn(), + setRef: vi.fn(), + selectStory: vi.fn(), + }; + const moduleArgs = createMockModuleArgs({ fullAPI }); + initStories(moduleArgs as unknown as ModuleArgs); + const { provider } = moduleArgs; + + getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); + provider.channel.emit(SELECT_STORY, { + kind: 'a', + story: '1', + viewMode: 'story', + }); + + expect(fullAPI.selectStory).toHaveBeenCalledWith(undefined, undefined, { + viewMode: 'story', + }); + }); + }); + describe('SET_CONFIG', () => { it('ignores sidebar.filters when config arrives after the index', async () => { const moduleArgs = createMockModuleArgs({ diff --git a/code/core/src/manager/components/sidebar/SearchResults.stories.tsx b/code/core/src/manager/components/sidebar/SearchResults.stories.tsx index 81557a92fb4b..e07626eb30c0 100644 --- a/code/core/src/manager/components/sidebar/SearchResults.stories.tsx +++ b/code/core/src/manager/components/sidebar/SearchResults.stories.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import type { StoriesHash } from 'storybook/manager-api'; +import type { IndexHash } from 'storybook/manager-api'; import { searchItem } from '../../utils/tree.ts'; import { IconSymbols } from './IconSymbols.tsx'; @@ -24,7 +24,7 @@ export default { ], }; -const combinedDataset = (refs: Record): CombinedDataset => { +const combinedDataset = (refs: Record): CombinedDataset => { const hash = Object.entries(refs).reduce( (acc, [refId, index]) => Object.assign(acc, { diff --git a/code/core/src/manager/components/sidebar/StatusContext.tsx b/code/core/src/manager/components/sidebar/StatusContext.tsx index 2ace18ec83e6..31be67131397 100644 --- a/code/core/src/manager/components/sidebar/StatusContext.tsx +++ b/code/core/src/manager/components/sidebar/StatusContext.tsx @@ -7,13 +7,13 @@ import type { StoryId, } from 'storybook/internal/types'; -import type { StoriesHash } from 'storybook/manager-api'; +import type { IndexHash } from 'storybook/manager-api'; import type { Item } from '../../container/Sidebar.tsx'; import { getDescendantIds } from '../../utils/tree.ts'; export const StatusContext = createContext<{ - data?: StoriesHash; + data?: IndexHash; allStatuses?: StatusesByStoryIdAndTypeId; groupStatus?: Record; }>({}); diff --git a/code/core/src/manager/components/sidebar/Tree.tsx b/code/core/src/manager/components/sidebar/Tree.tsx index 7dc7fd540cb3..b61e8971a251 100644 --- a/code/core/src/manager/components/sidebar/Tree.tsx +++ b/code/core/src/manager/components/sidebar/Tree.tsx @@ -19,13 +19,7 @@ import { CollapseIcon as CollapseIconSvg, ExpandAltIcon } from '@storybook/icons import { internal_fullStatusStore as fullStatusStore } from '#manager-stores'; import { darken } from 'polished'; import { useStorybookApi, useStorybookState } from 'storybook/manager-api'; -import type { - API, - ComponentEntry, - GroupEntry, - StoriesHash, - StoryEntry, -} from 'storybook/manager-api'; +import type { API, ComponentEntry, GroupEntry, IndexHash, StoryEntry } from 'storybook/manager-api'; import { styled, useTheme } from 'storybook/theming'; import type { Link } from '../../../components/components/tooltip/TooltipLinkList.tsx'; @@ -607,7 +601,7 @@ export const Tree = React.memo<{ isMain: boolean; allStatuses?: StatusesByStoryIdAndTypeId; refId: string; - data: StoriesHash; + data: IndexHash; docsMode: boolean; highlightedRef: MutableRefObject; setHighlightedItemId: (itemId: string) => void; diff --git a/code/core/src/manager/components/sidebar/types.ts b/code/core/src/manager/components/sidebar/types.ts index 338a1acde05d..e1a1c900f773 100644 --- a/code/core/src/manager/components/sidebar/types.ts +++ b/code/core/src/manager/components/sidebar/types.ts @@ -1,11 +1,13 @@ import type { StatusValue, StatusesByStoryIdAndTypeId } from 'storybook/internal/types'; import type { ControllerStateAndHelpers } from 'downshift'; -import type { State, StoriesHash } from 'storybook/manager-api'; +import type { IndexHash, State } from 'storybook/manager-api'; export type Refs = State['refs']; -export type RefType = Refs[keyof Refs] & { allStatuses?: StatusesByStoryIdAndTypeId }; -export type Item = StoriesHash[keyof StoriesHash]; +export type RefType = Refs[keyof Refs] & { + allStatuses?: StatusesByStoryIdAndTypeId; +}; +export type Item = IndexHash[keyof IndexHash]; export type Dataset = Record; export interface CombinedDataset { @@ -45,7 +47,11 @@ export interface ExpandType { moreCount: number; } -export type SearchItem = Item & { refId: string; path: string[]; status?: StatusValue }; +export type SearchItem = Item & { + refId: string; + path: string[]; + status?: StatusValue; +}; export type SearchResult = Fuse.FuseResultWithMatches & Fuse.FuseResultWithScore; diff --git a/code/core/src/manager/components/sidebar/useExpanded.ts b/code/core/src/manager/components/sidebar/useExpanded.ts index cf42f9d103ba..afa30752ce86 100644 --- a/code/core/src/manager/components/sidebar/useExpanded.ts +++ b/code/core/src/manager/components/sidebar/useExpanded.ts @@ -6,7 +6,7 @@ import { STORIES_COLLAPSE_ALL, STORIES_EXPAND_ALL } from 'storybook/internal/cor import { global } from '@storybook/global'; import { throttle } from 'es-toolkit/function'; -import type { StoriesHash } from 'storybook/manager-api'; +import type { IndexHash } from 'storybook/manager-api'; import { useStorybookApi } from 'storybook/manager-api'; import { matchesKeyCode, matchesModifiers } from '../../keybinding.ts'; @@ -26,7 +26,7 @@ export interface ExpandedProps { containerRef: MutableRefObject; isBrowsing: boolean; refId: string; - data: StoriesHash; + data: IndexHash; initialExpanded?: ExpandedState; rootIds: string[]; highlightedRef: MutableRefObject; @@ -44,7 +44,7 @@ const initializeExpanded = ({ selectedStoryId, }: { refId: string; - data: StoriesHash; + data: IndexHash; initialExpanded?: ExpandedState; highlightedRef: MutableRefObject; rootIds: string[]; @@ -87,7 +87,7 @@ export const useExpanded = ({ Reducer, { refId: string; - data: StoriesHash; + data: IndexHash; highlightedRef: MutableRefObject; rootIds: string[]; initialExpanded: ExpandedState; diff --git a/code/core/src/manager/container/Preview.tsx b/code/core/src/manager/container/Preview.tsx index a4641ae57eac..ee319fb72223 100644 --- a/code/core/src/manager/container/Preview.tsx +++ b/code/core/src/manager/container/Preview.tsx @@ -5,7 +5,7 @@ import type { Addon_BaseType, Addon_Collection, Addon_WrapperType } from 'storyb import { Addon_TypesEnum } from 'storybook/internal/types'; import memoizerific from 'memoizerific'; -import type { State, StoriesHash } from 'storybook/manager-api'; +import type { IndexHash, State } from 'storybook/manager-api'; import { Consumer } from 'storybook/manager-api'; import { Preview } from '../components/preview/Preview.tsx'; @@ -48,7 +48,7 @@ const memoizedWrapper = memoizerific(1)((_, previewElements: Addon_Collection) = ...Object.values(previewElements), ]); -export type Item = StoriesHash[keyof StoriesHash]; +export type Item = IndexHash[keyof IndexHash]; const splitTitleAddExtraSpace = (input: string) => input.split('/').join(' / ').replace(/\s\s/, ' '); diff --git a/code/core/src/manager/container/Sidebar.tsx b/code/core/src/manager/container/Sidebar.tsx index 3f0b100770f2..2a47c38b3d45 100755 --- a/code/core/src/manager/container/Sidebar.tsx +++ b/code/core/src/manager/container/Sidebar.tsx @@ -1,13 +1,13 @@ import React from 'react'; -import type { Combo, StoriesHash } from 'storybook/manager-api'; +import type { Combo, IndexHash } from 'storybook/manager-api'; import { Consumer, experimental_useStatusStore } from 'storybook/manager-api'; import type { SidebarProps as SidebarComponentProps } from '../components/sidebar/Sidebar.tsx'; import { Sidebar as SidebarComponent } from '../components/sidebar/Sidebar.tsx'; import { useMenu } from './Menu.tsx'; -export type Item = StoriesHash[keyof StoriesHash]; +export type Item = IndexHash[keyof IndexHash]; interface SidebarProps { onMenuClick?: SidebarComponentProps['onMenuClick']; diff --git a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts index 6024e258e20a..e99be5231b04 100644 --- a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts +++ b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts @@ -84,7 +84,9 @@ export class StoryRender implements Render, private renderToScreen: RenderToCanvas, - private callbacks: RenderContextCallbacks & { showStoryDuringRender?: () => void }, + private callbacks: RenderContextCallbacks & { + showStoryDuringRender?: () => void; + }, public id: StoryId, public viewMode: StoryContext['viewMode'], public renderOptions: StoryRenderOptions = { autoplay: true, forceInitialArgs: false }, @@ -272,10 +274,8 @@ export class StoryRender implements Render = { componentId, title, - kind: title, id, name, - story: name, tags, ...this.callbacks, showError: (error) => { diff --git a/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts b/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts index 1e93b7795a07..61281191e281 100644 --- a/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts +++ b/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts @@ -855,7 +855,6 @@ describe('prepareMeta', () => { // omitting the properties from preparedStory that are not in preparedMeta const { name: storyName, - story, applyLoaders, applyBeforeEach, applyAfterEach, diff --git a/code/core/src/preview-api/modules/store/csf/prepareStory.ts b/code/core/src/preview-api/modules/store/csf/prepareStory.ts index 0ebc1ba660bd..4d231fd25145 100644 --- a/code/core/src/preview-api/modules/store/csf/prepareStory.ts +++ b/code/core/src/preview-api/modules/store/csf/prepareStory.ts @@ -153,7 +153,6 @@ export function prepareStory( moduleExport, id, name, - story: name, originalStoryFn: render!, undecoratedStoryFn, unboundStoryFn, @@ -251,11 +250,9 @@ function preparePartialAnnotations( } = { componentId: componentAnnotations.id, title: componentAnnotations.title, - kind: componentAnnotations.title, // Back compat id: storyAnnotations?.id || componentAnnotations.id, // if there's no story name, we create a fake one since enhancers expect a name name: storyAnnotations?.name || '__meta', - story: storyAnnotations?.name || '__meta', // Back compat component: componentAnnotations.component, subcomponents: componentAnnotations.subcomponents, tags, @@ -293,7 +290,7 @@ function preparePartialAnnotations( initialArgsBeforeEnhancers ); - const { name, story, ...withoutStoryIdentifiers } = contextForEnhancers; + const { name, ...withoutStoryIdentifiers } = contextForEnhancers; return withoutStoryIdentifiers; } diff --git a/code/core/src/preview-api/modules/store/decorators.test.ts b/code/core/src/preview-api/modules/store/decorators.test.ts index 850673451637..892147ad94d5 100644 --- a/code/core/src/preview-api/modules/store/decorators.test.ts +++ b/code/core/src/preview-api/modules/store/decorators.test.ts @@ -7,7 +7,6 @@ import { defaultDecorateStory } from './decorators.ts'; function makeContext(input: Record = {}): StoryContextForRender { return { id: 'id', - kind: 'kind', name: 'name', viewMode: 'story', parameters: {}, @@ -122,17 +121,23 @@ describe('client-api.decorators', () => { const contexts: StoryContextForRender[] = []; const decorators = [ // @ts-expect-error (not defined) - (s, c) => - contexts.push(c) && - s({ parameters: { c: 'd' }, id: 'notId', kind: 'notKind', name: 'notName' }), + (s, c) => contexts.push(c) && s({ parameters: { c: 'd' }, id: 'notId', name: 'notName' }), ]; const decorated = defaultDecorateStory((c) => contexts.push(c), decorators); expect(contexts).toEqual([]); decorated(makeContext({ parameters: { a: 'b' } })); expect(contexts).toEqual([ - expect.objectContaining({ parameters: { a: 'b' }, id: 'id', kind: 'kind', name: 'name' }), - expect.objectContaining({ parameters: { a: 'b' }, id: 'id', kind: 'kind', name: 'name' }), + expect.objectContaining({ + parameters: { a: 'b' }, + id: 'id', + name: 'name', + }), + expect.objectContaining({ + parameters: { a: 'b' }, + id: 'id', + name: 'name', + }), ]); }); }); diff --git a/code/core/src/preview-api/modules/store/decorators.ts b/code/core/src/preview-api/modules/store/decorators.ts index 0953fbfd14fc..07af1702cc7b 100644 --- a/code/core/src/preview-api/modules/store/decorators.ts +++ b/code/core/src/preview-api/modules/store/decorators.ts @@ -30,10 +30,8 @@ export function decorateStory( export function sanitizeStoryContextUpdate({ componentId, title, - kind, id, name, - story, parameters, initialArgs, argTypes, diff --git a/code/core/src/types/modules/addons.ts b/code/core/src/types/modules/addons.ts index ef3605e5f9ac..e95331e02b7e 100644 --- a/code/core/src/types/modules/addons.ts +++ b/code/core/src/types/modules/addons.ts @@ -17,7 +17,6 @@ import type { StoryContextForRender as StoryContextForFramework, StoryFn as StoryFnForFramework, StoryId, - StoryKind, StoryName, } from './csf.ts'; import type { IndexEntry } from './indexer.ts'; @@ -121,7 +120,6 @@ export type Addon_MakeDecoratorResult = (...args: any) => any; export interface Addon_AddStoryArgs { id: StoryId; - kind: StoryKind; name: StoryName; storyFn: Addon_StoryFn; parameters: Parameters; @@ -140,7 +138,6 @@ export type Addon_ClientApiReturnFn = ( ) => Addon_StoryApi; export interface Addon_StoryApi { - kind: StoryKind; add: ( storyName: StoryName, storyFn: Addon_StoryFn, diff --git a/code/core/src/types/modules/channelApi.ts b/code/core/src/types/modules/channelApi.ts index 6935f7145475..b8e30448f8ad 100644 --- a/code/core/src/types/modules/channelApi.ts +++ b/code/core/src/types/modules/channelApi.ts @@ -7,7 +7,6 @@ import type { Globals, Parameters, StoryId, - StoryKind, } from './csf.ts'; // The data received on the (legacy) `setStories` event @@ -16,7 +15,6 @@ export interface SetStoriesStory { name: string; refId?: string; componentId?: ComponentId; - kind: StoryKind; parameters: { fileName: string; options: { diff --git a/code/core/src/types/modules/csf.ts b/code/core/src/types/modules/csf.ts index 72c5419f7c38..1a05ac191431 100644 --- a/code/core/src/types/modules/csf.ts +++ b/code/core/src/types/modules/csf.ts @@ -34,7 +34,6 @@ export type { Parameters, PartialStoryFn, PlayFunction, - PlayFunctionContext, Renderer, SBArrayType, SBEnumType, @@ -52,13 +51,11 @@ export type { StoryAnnotationsOrFn, StoryContext, StoryContextForEnhancers, - StoryContextForLoaders, StoryContextForRender, StoryContextUpdate, StoryFn, StoryId, StoryIdentifier, - StoryKind, StoryName, StrictArgs, StrictArgTypes, diff --git a/code/core/template/stories/argMapping.stories.ts b/code/core/template/stories/argMapping.stories.ts index ea77d3edfddc..4732c421e843 100644 --- a/code/core/template/stories/argMapping.stories.ts +++ b/code/core/template/stories/argMapping.stories.ts @@ -1,4 +1,4 @@ -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -43,7 +43,7 @@ export const Single = { }, }, }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({ mappingArg: { name: 'ArrowRight' }, }); @@ -64,7 +64,7 @@ export const Multiple = { }, }, }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({ mappingArg: [{ name: 'ArrowRight' }, { name: 'ArrowLeft' }], }); diff --git a/code/core/template/stories/argTypes.stories.ts b/code/core/template/stories/argTypes.stories.ts index d285779480f8..1b85a6d8057e 100644 --- a/code/core/template/stories/argTypes.stories.ts +++ b/code/core/template/stories/argTypes.stories.ts @@ -1,8 +1,4 @@ -import type { - PartialStoryFn, - PlayFunctionContext, - StoryContextForRender, -} from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext, StoryContextForRender } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -27,7 +23,7 @@ export const Inheritance = { storyArg: { type: 'number' }, composedArg: { options: ['a', 'b'] }, }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { // NOTE: these stories don't test project-level argTypes inheritance as it is too problematic // to have an argType floating around that will apply too *all* other stories in our sandboxes. await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({ @@ -47,7 +43,7 @@ export const ArgTypeInference = { d: { a: 'b' }, e: ['a', 'b'], }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const argTypes = JSON.parse(within(canvasElement).getByTestId('pre').innerText); // `prepareStory` skips `inferArgTypes` when `docgenServer` is on; the manager // runs that second pass in `mergeServiceArgTypes`, so the preview canvas never sees types @@ -72,7 +68,7 @@ export const ArgTypeInference = { }; export const HiddenFromPlay = { - play: async (context: PlayFunctionContext) => { + play: async (context: StoryContext) => { expect('argTypes' in context).toBe(false); expect(() => context.argTypes).toThrow(/no longer part of the story context/); }, diff --git a/code/core/template/stories/args.stories.ts b/code/core/template/stories/args.stories.ts index e1760c784a3b..b4d6b5815f4a 100644 --- a/code/core/template/stories/args.stories.ts +++ b/code/core/template/stories/args.stories.ts @@ -3,7 +3,7 @@ import { STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, } from 'storybook/internal/core-events'; -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -46,7 +46,7 @@ export const Inheritance = { a: 'story', }, }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { // NOTE: these stories don't test project-level args inheritance as it is too problematic // to have an arg floating around that will apply too *all* other stories in our sandboxes. await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toEqual({ @@ -68,7 +68,7 @@ export const Targets = { a: { target: 'elsewhere' }, }, parameters: { argNames: ['a', 'b'] }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { // Check that `a` doesn't end up set await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toEqual({ b: 'b', @@ -82,7 +82,7 @@ export const Events = { test: 'initial', }, parameters: { argNames: ['test'] }, - play: async ({ canvasElement, id }: PlayFunctionContext) => { + play: async ({ canvasElement, id }: StoryContext) => { const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; await channel.emit(RESET_STORY_ARGS, { storyId: id }); await new Promise((resolve) => channel.once(STORY_ARGS_UPDATED, resolve)); diff --git a/code/core/template/stories/autotitle.stories.ts b/code/core/template/stories/autotitle.stories.ts index 5fa47cbe32ab..11068b43037d 100644 --- a/code/core/template/stories/autotitle.stories.ts +++ b/code/core/template/stories/autotitle.stories.ts @@ -1,4 +1,4 @@ -import type { PlayFunctionContext } from 'storybook/internal/types'; +import type { StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -10,7 +10,7 @@ export default { }; export const Default = { - play: async ({ title }: PlayFunctionContext) => { + play: async ({ title }: StoryContext) => { await expect(title).toBe('core/autotitle'); }, }; diff --git a/code/core/template/stories/component-play.stories.ts b/code/core/template/stories/component-play.stories.ts index 729cbf882ed1..ccb7443e119a 100644 --- a/code/core/template/stories/component-play.stories.ts +++ b/code/core/template/stories/component-play.stories.ts @@ -1,4 +1,4 @@ -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -6,7 +6,7 @@ import { expect, within } from 'storybook/test'; export default { component: globalThis.__TEMPLATE_COMPONENTS__.Pre, - play: async ({ canvasElement, name }: PlayFunctionContext) => { + play: async ({ canvasElement, name }: StoryContext) => { await expect( JSON.parse(within(canvasElement as HTMLPreElement).getByTestId('pre').innerText) ).toEqual({ diff --git a/code/core/template/stories/decorators.stories.ts b/code/core/template/stories/decorators.stories.ts index ea220afdf2c8..cbe39e07fd77 100644 --- a/code/core/template/stories/decorators.stories.ts +++ b/code/core/template/stories/decorators.stories.ts @@ -6,7 +6,6 @@ import { import type { ArgsStoryFn, PartialStoryFn, - PlayFunctionContext, StoryContext, StoryContextForRender, } from 'storybook/internal/types'; @@ -33,7 +32,7 @@ export const Inheritance = { args: { text: 'starting', }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const canvas = within(canvasElement); await expect(canvas.getByTestId('pre').innerText).toEqual('story component project starting'); }, @@ -58,7 +57,7 @@ export const Hooks = { text: 'text', condition: true, }, - play: async ({ id, args }: PlayFunctionContext) => { + play: async ({ id, args }: StoryContext) => { const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; await channel.emit(RESET_STORY_ARGS, { storyId: id }); await new Promise((resolve) => channel.once(STORY_ARGS_UPDATED, resolve)); diff --git a/code/core/template/stories/globals.stories.ts b/code/core/template/stories/globals.stories.ts index 15bbf6acd55e..b620735ec8f2 100644 --- a/code/core/template/stories/globals.stories.ts +++ b/code/core/template/stories/globals.stories.ts @@ -1,4 +1,4 @@ -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -18,7 +18,7 @@ export const Inheritance = { (storyFn: PartialStoryFn, context: StoryContext) => storyFn({ args: { object: context.globals } }), ], - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({ foo: 'fooValue', bar: 'barValue', @@ -34,7 +34,7 @@ export const Events = { (storyFn: PartialStoryFn, context: StoryContext) => storyFn({ args: { text: context.globals.foo } }), ], - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; await channel.emit('updateGlobals', { globals: { foo: 'fooValue' } }); await within(canvasElement).findByText('fooValue'); @@ -60,7 +60,7 @@ export const Overrides1 = { foo: 'fooOverridden1', baz: 'bazOverridden1', }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({ foo: 'fooOverridden1', bar: 'barValue', @@ -79,7 +79,7 @@ export const Overrides2 = { foo: 'fooOverridden2', baz: 'bazOverridden2', }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({ foo: 'fooOverridden2', bar: 'barValue', diff --git a/code/core/template/stories/indexer.stories.ts b/code/core/template/stories/indexer.stories.ts index 1b03c38bd029..d22e7161228f 100644 --- a/code/core/template/stories/indexer.stories.ts +++ b/code/core/template/stories/indexer.stories.ts @@ -1,4 +1,4 @@ -import type { PlayFunctionContext } from 'storybook/internal/types'; +import type { StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -11,7 +11,7 @@ export default { }; export const Default = { - play: async ({ id }: PlayFunctionContext) => { + play: async ({ id }: StoryContext) => { await expect(id).toBe('indexer-custom-meta-id--default'); }, }; @@ -20,7 +20,7 @@ export const CustomParametersId = { parameters: { __id: 'custom-id', }, - play: async ({ id }: PlayFunctionContext) => { + play: async ({ id }: StoryContext) => { await expect(id).toBe('custom-id'); }, }; diff --git a/code/core/template/stories/names.stories.ts b/code/core/template/stories/names.stories.ts index f87b1f8aafa3..b028c9b3c94b 100644 --- a/code/core/template/stories/names.stories.ts +++ b/code/core/template/stories/names.stories.ts @@ -1,4 +1,4 @@ -import type { PlayFunctionContext } from 'storybook/internal/types'; +import type { StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -13,13 +13,13 @@ export default { // Repro for https://github.com/storybookjs/storybook/issues/11571 export const PrefixAndName = { - play: async ({ name }: PlayFunctionContext) => { + play: async ({ name }: StoryContext) => { await expect(name).toBe('Prefix And Name'); }, }; export const Prefix = { - play: async ({ name }: PlayFunctionContext) => { + play: async ({ name }: StoryContext) => { await expect(name).toBe('Prefix'); }, }; diff --git a/code/core/template/stories/parameters.stories.ts b/code/core/template/stories/parameters.stories.ts index 7c8c1e00c29b..6583195346a1 100644 --- a/code/core/template/stories/parameters.stories.ts +++ b/code/core/template/stories/parameters.stories.ts @@ -1,4 +1,4 @@ -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -32,7 +32,7 @@ export const Inheritance = { a: 'story', }, }, - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const canvas = within(canvasElement); await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({ projectParameter: 'projectParameter', diff --git a/code/core/template/stories/rendering.stories.ts b/code/core/template/stories/rendering.stories.ts index 8d98901d6396..ca3a55ab5fa6 100644 --- a/code/core/template/stories/rendering.stories.ts +++ b/code/core/template/stories/rendering.stories.ts @@ -4,7 +4,7 @@ import { STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, } from 'storybook/internal/core-events'; -import type { PlayFunctionContext } from 'storybook/internal/types'; +import type { StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -27,7 +27,7 @@ export const ForceRemount = { * FORCE_REMOUNT event */ parameters: { chromatic: { disableSnapshot: true } }, - play: async ({ canvasElement, id }: PlayFunctionContext) => { + play: async ({ canvasElement, id }: StoryContext) => { const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; const button = await within(canvasElement).findByRole('button'); @@ -76,7 +76,7 @@ export const SlowLoader = { }; export const ChangeArgs = { - play: async ({ canvasElement, id }: PlayFunctionContext) => { + play: async ({ canvasElement, id }: StoryContext) => { const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; await channel.emit(RESET_STORY_ARGS, { storyId: id }); diff --git a/code/core/template/stories/shortcuts.stories.ts b/code/core/template/stories/shortcuts.stories.ts index 2db1beaf58d1..54a6ce0ecb58 100644 --- a/code/core/template/stories/shortcuts.stories.ts +++ b/code/core/template/stories/shortcuts.stories.ts @@ -1,5 +1,5 @@ import { PREVIEW_KEYDOWN } from 'storybook/internal/core-events'; -import type { PlayFunctionContext } from 'storybook/internal/csf'; +import type { StoryContext } from 'storybook/internal/csf'; import { global as globalThis } from '@storybook/global'; @@ -15,7 +15,7 @@ export default { }; export const KeydownDuringPlay = { - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; const previewKeydown = fn(); diff --git a/code/core/template/stories/tags-add.stories.ts b/code/core/template/stories/tags-add.stories.ts index 8f330a5eca0e..cbca939ffbde 100644 --- a/code/core/template/stories/tags-add.stories.ts +++ b/code/core/template/stories/tags-add.stories.ts @@ -1,4 +1,4 @@ -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -19,7 +19,7 @@ export default { export const Inheritance = { tags: ['story-one', '!vitest'], - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const canvas = within(canvasElement); await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({ tags: ['story-one'], diff --git a/code/core/template/stories/tags-config.stories.ts b/code/core/template/stories/tags-config.stories.ts index 73241353cb7f..38bc5c368f77 100644 --- a/code/core/template/stories/tags-config.stories.ts +++ b/code/core/template/stories/tags-config.stories.ts @@ -1,4 +1,4 @@ -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -19,7 +19,7 @@ export default { export const Inheritance = { tags: ['story-one', '!vitest'], - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const canvas = within(canvasElement); await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({ tags: ['dev', 'test', 'component-one', 'component-two', 'autodocs', 'story-one'], diff --git a/code/core/template/stories/tags-remove.stories.ts b/code/core/template/stories/tags-remove.stories.ts index 10b95a2932d7..3ad0b001d719 100644 --- a/code/core/template/stories/tags-remove.stories.ts +++ b/code/core/template/stories/tags-remove.stories.ts @@ -1,4 +1,4 @@ -import type { PartialStoryFn, PlayFunctionContext, StoryContext } from 'storybook/internal/types'; +import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -19,7 +19,7 @@ export default { export const Inheritance = { tags: ['story-one', '!vitest'], - play: async ({ canvasElement }: PlayFunctionContext) => { + play: async ({ canvasElement }: StoryContext) => { const canvas = within(canvasElement); await expect(JSON.parse(canvas.getByTestId('pre').innerText)).toEqual({ tags: ['dev', 'test', 'component-one', 'autodocs', 'story-one'], diff --git a/code/core/template/stories/title.stories.ts b/code/core/template/stories/title.stories.ts index d8c432447616..609ceb64ee1b 100644 --- a/code/core/template/stories/title.stories.ts +++ b/code/core/template/stories/title.stories.ts @@ -1,4 +1,4 @@ -import type { PlayFunctionContext } from 'storybook/internal/types'; +import type { StoryContext } from 'storybook/internal/types'; import { global as globalThis } from '@storybook/global'; @@ -11,7 +11,7 @@ export default { }; export const Default = { - play: async ({ title }: PlayFunctionContext) => { + play: async ({ title }: StoryContext) => { await expect(title).toBe('core/manual title'); }, }; diff --git a/code/frameworks/ember/src/client/preview/render.ts b/code/frameworks/ember/src/client/preview/render.ts index 46068ae0a131..f26f8fb8f88b 100644 --- a/code/frameworks/ember/src/client/preview/render.ts +++ b/code/frameworks/ember/src/client/preview/render.ts @@ -69,14 +69,14 @@ function render(options: OptionsArgs, el: EmberRenderer['canvasElement']) { } export function renderToCanvas( - { storyFn, kind, name, showMain, showError }: RenderContext, + { storyFn, title, name, showMain, showError }: RenderContext, canvasElement: EmberRenderer['canvasElement'] ) { const element = storyFn(); if (!element) { showError({ - title: `Expecting a Ember element from the story: "${name}" of "${kind}".`, + title: `Expecting a Ember element from the story: "${name}" of "${title}".`, description: dedent` Did you forget to return the Ember element from the story? Use "() => hbs('{{component}}')" or "() => { return { diff --git a/code/renderers/html/src/render.ts b/code/renderers/html/src/render.ts index 987ff763c055..6e2c6a281ddd 100644 --- a/code/renderers/html/src/render.ts +++ b/code/renderers/html/src/render.ts @@ -42,7 +42,7 @@ export const render: ArgsStoryFn = (args, context) => { }; export function renderToCanvas( - { storyFn, kind, name, showMain, showError, forceRemount }: RenderContext, + { storyFn, title, name, showMain, showError, forceRemount }: RenderContext, canvasElement: HtmlRenderer['canvasElement'] ) { const element = storyFn(); @@ -60,7 +60,7 @@ export function renderToCanvas( simulateDOMContentLoaded(); } else { showError({ - title: `Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`, + title: `Expecting an HTML snippet or DOM node from the story: "${name}" of "${title}".`, description: dedent` Did you forget to return the HTML snippet from the story? Use "() => " or when defining the story. diff --git a/code/renderers/web-components/src/render.ts b/code/renderers/web-components/src/render.ts index c2d771c88788..f2bd87c0f28a 100644 --- a/code/renderers/web-components/src/render.ts +++ b/code/renderers/web-components/src/render.ts @@ -41,7 +41,7 @@ export const render: ArgsStoryFn = (args, context) => { }; export function renderToCanvas( - { storyFn, kind, name, showMain, showError, forceRemount }: RenderContext, + { storyFn, title, name, showMain, showError, forceRemount }: RenderContext, canvasElement: WebComponentsRenderer['canvasElement'] ): void { const element = storyFn(); @@ -72,7 +72,7 @@ export function renderToCanvas( simulateDOMContentLoaded(); } else { showError({ - title: `Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`, + title: `Expecting an HTML snippet or DOM node from the story: "${name}" of "${title}".`, description: dedent` Did you forget to return the HTML snippet from the story? Use "() => " or when defining the story. From 706cc43bf54c1dd7ea2f7a241672b7a14aa17d77 Mon Sep 17 00:00:00 2001 From: Obvious Date: Fri, 9 Oct 2026 15:52:37 +0000 Subject: [PATCH 2/8] refactor(manager-api): drop legacy kind/story from SELECT_STORY and snapshots SELECT_STORY no longer accepts the pre-CSF3 `kind`/`story` payload spellings: the handler destructures and discards them so they neither resolve a story nor leak into the forwarded options. StoryStore and PreviewWeb inline snapshots drop the removed back-compat keys. --- code/core/src/manager-api/modules/stories.ts | 7 +++++++ .../preview-api/modules/preview-web/PreviewWeb.test.ts | 8 -------- .../core/src/preview-api/modules/store/StoryStore.test.ts | 8 -------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/code/core/src/manager-api/modules/stories.ts b/code/core/src/manager-api/modules/stories.ts index 6317827d4061..35d8f403bfba 100644 --- a/code/core/src/manager-api/modules/stories.ts +++ b/code/core/src/manager-api/modules/stories.ts @@ -1265,12 +1265,19 @@ export const init: ModuleFn = ({ title, name, storyId, + kind, + story, ...rest }: { title?: ComponentTitle; name?: StoryName; storyId: string; viewMode: API_ViewMode; + // Legacy pre-CSF3 spellings: dropped so they neither resolve nor leak into options. + /** @deprecated */ + kind?: unknown; + /** @deprecated */ + story?: unknown; } ) { const { ref } = getEventMetadata(this, fullAPI)!; diff --git a/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts b/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts index 01712a252b53..0501cb0f37ba 100644 --- a/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts +++ b/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts @@ -3919,7 +3919,6 @@ describe('PreviewWeb', () => { "foo": "a", "one": 1, }, - "kind": "Component One", "name": "A", "parameters": { "__isArgsStory": false, @@ -3939,7 +3938,6 @@ describe('PreviewWeb', () => { "fileName": "./src/ComponentOne.stories.js", "throwPlayFunctionExceptions": false, }, - "story": "A", "storyGlobals": {}, "storyId": "component-one--a", "subcomponents": undefined, @@ -3993,7 +3991,6 @@ describe('PreviewWeb', () => { "foo": "b", "one": 1, }, - "kind": "Component One", "name": "B", "parameters": { "__isArgsStory": false, @@ -4013,7 +4010,6 @@ describe('PreviewWeb', () => { "fileName": "./src/ComponentOne.stories.js", "throwPlayFunctionExceptions": false, }, - "story": "B", "storyGlobals": {}, "storyId": "component-one--b", "subcomponents": undefined, @@ -4045,7 +4041,6 @@ describe('PreviewWeb', () => { }, "id": "component-one--e", "initialArgs": {}, - "kind": "Component One", "name": "E", "parameters": { "__isArgsStory": false, @@ -4065,7 +4060,6 @@ describe('PreviewWeb', () => { "throwPlayFunctionExceptions": false, }, "playFunction": undefined, - "story": "E", "storyGlobals": {}, "storyId": "component-one--e", "subcomponents": undefined, @@ -4108,7 +4102,6 @@ describe('PreviewWeb', () => { "initialArgs": { "foo": "c", }, - "kind": "Component Two", "name": "C", "parameters": { "__isArgsStory": false, @@ -4127,7 +4120,6 @@ describe('PreviewWeb', () => { "throwPlayFunctionExceptions": false, }, "playFunction": undefined, - "story": "C", "storyGlobals": {}, "storyId": "component-two--c", "subcomponents": undefined, diff --git a/code/core/src/preview-api/modules/store/StoryStore.test.ts b/code/core/src/preview-api/modules/store/StoryStore.test.ts index f4507af894c6..4a33ab099dcf 100644 --- a/code/core/src/preview-api/modules/store/StoryStore.test.ts +++ b/code/core/src/preview-api/modules/store/StoryStore.test.ts @@ -379,7 +379,6 @@ describe('StoryStore', () => { "initialArgs": { "foo": "a", }, - "kind": "Component One", "name": "A", "parameters": { "__isArgsStory": false, @@ -396,7 +395,6 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, - "story": "A", "storyGlobals": {}, "storyId": "component-one--a", "subcomponents": undefined, @@ -577,7 +575,6 @@ describe('StoryStore', () => { "initialArgs": { "foo": "a", }, - "kind": "Component One", "name": "A", "parameters": { "__isArgsStory": false, @@ -594,7 +591,6 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, - "story": "A", "storyGlobals": {}, "storyId": "component-one--a", "subcomponents": undefined, @@ -644,7 +640,6 @@ describe('StoryStore', () => { "initialArgs": { "foo": "b", }, - "kind": "Component One", "name": "B", "parameters": { "__isArgsStory": false, @@ -661,7 +656,6 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, - "story": "B", "storyGlobals": {}, "storyId": "component-one--b", "subcomponents": undefined, @@ -710,7 +704,6 @@ describe('StoryStore', () => { "initialArgs": { "foo": "c", }, - "kind": "Component Two", "name": "C", "parameters": { "__isArgsStory": false, @@ -727,7 +720,6 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, - "story": "C", "storyGlobals": {}, "storyId": "component-two--c", "subcomponents": undefined, From 5f2c01533faede29aaed1c0f6a96dc414a5b6c3b Mon Sep 17 00:00:00 2001 From: Obvious Date: Fri, 9 Oct 2026 16:26:36 +0000 Subject: [PATCH 3/8] test(angular,react): drop legacy kind/story from fixture contexts The three fixtures still wrote the removed StoryIdentifier back-compat fields, breaking the repo typecheck: the angular makeContext literals carried kind: 'kind' and the react RenderToCanvas play fixture passed context.kind/context.story into RenderContext. Use the surviving title/name-based fields only. --- code/frameworks/angular-vite/src/client/decorateStory.test.ts | 1 - code/frameworks/angular/src/client/decorateStory.test.ts | 1 - code/renderers/react/src/__test__/RenderToCanvas.stories.tsx | 2 -- 3 files changed, 4 deletions(-) diff --git a/code/frameworks/angular-vite/src/client/decorateStory.test.ts b/code/frameworks/angular-vite/src/client/decorateStory.test.ts index cce2901baeaa..e271843d6ba7 100644 --- a/code/frameworks/angular-vite/src/client/decorateStory.test.ts +++ b/code/frameworks/angular-vite/src/client/decorateStory.test.ts @@ -337,7 +337,6 @@ describe('decorateStory', () => { function makeContext(input: Record): StoryContextForRender { return { id: 'id', - kind: 'kind', name: 'name', viewMode: 'story', parameters: {}, diff --git a/code/frameworks/angular/src/client/decorateStory.test.ts b/code/frameworks/angular/src/client/decorateStory.test.ts index 016c23a7f250..3b3eb6b0b3cb 100644 --- a/code/frameworks/angular/src/client/decorateStory.test.ts +++ b/code/frameworks/angular/src/client/decorateStory.test.ts @@ -332,7 +332,6 @@ describe.skip('decorateStory', () => { function makeContext(input: Record): StoryContextForRender { return { id: 'id', - kind: 'kind', name: 'name', viewMode: 'story', parameters: {}, diff --git a/code/renderers/react/src/__test__/RenderToCanvas.stories.tsx b/code/renderers/react/src/__test__/RenderToCanvas.stories.tsx index a343a430129c..c4bbaf982beb 100644 --- a/code/renderers/react/src/__test__/RenderToCanvas.stories.tsx +++ b/code/renderers/react/src/__test__/RenderToCanvas.stories.tsx @@ -39,10 +39,8 @@ export const AwaitsDocsLayoutEffects: Story = { { componentId: context.componentId, title: context.title, - kind: context.kind, id: context.id, name: context.name, - story: context.story, tags: context.tags, showMain: () => {}, showError: () => {}, From 2b45c35003921735500ba175a472d39a344d6e8e Mon Sep 17 00:00:00 2001 From: Obvious Date: Thu, 15 Oct 2026 12:24:11 +0000 Subject: [PATCH 4/8] fix: migrate addon-links to modern SELECT_STORY payloads and drop the legacy setStories receiver - Emit { title, name } payloads from linkTo and the data-sb-kind listener; the DOM attribute contract is unchanged - Type the receiver with SelectStoryPayload; warn and ignore payloads without storyId, title, or name - Remove the dead SET_STORIES composition receiver, denormalizeStoryParameters, API_StoryMapper, and StoryIndexV2 - Narrow setRef to storyIndex and fail unsupported index versions into the index error path - Add the missing MIGRATION.md table-of-contents anchor --- MIGRATION.md | 1 + code/addons/links/src/utils.test.ts | 12 +- code/addons/links/src/utils.ts | 12 +- code/core/src/manager-api/lib/stories.ts | 15 +-- code/core/src/manager-api/modules/refs.ts | 6 +- code/core/src/manager-api/modules/stories.ts | 60 +++------- .../src/manager-api/tests/stories.test.ts | 105 +++--------------- code/core/src/types/modules/api.ts | 5 - code/core/src/types/modules/channelApi.ts | 46 +------- code/core/src/types/modules/indexer.ts | 10 -- 10 files changed, 50 insertions(+), 222 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 14cf24e73004..aaef009e1ccf 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -14,6 +14,7 @@ - [Toolbar `globalTypes` entries: index signature and `defaultValue` removed](#toolbar-globaltypes-entries-index-signature-and-defaultvalue-removed) - [Docs Code panel enabled by default](#docs-code-panel-enabled-by-default) - [`argTypes` removed from loaders, `beforeEach`, `play` and `afterEach`](#argtypes-removed-from-loaders-beforeeach-play-and-aftereach) + - [Deprecated CSF and manager type aliases removed](#deprecated-csf-and-manager-type-aliases-removed) - [`docgenServer` is stable and enabled by default](#docgenserver-is-stable-and-enabled-by-default) - [Builder docgen is deprecated](#builder-docgen-is-deprecated) - [Node.js 22.12 or higher](#nodejs-2212-or-higher) diff --git a/code/addons/links/src/utils.test.ts b/code/addons/links/src/utils.test.ts index d946e007a31b..e0227e54deaa 100644 --- a/code/addons/links/src/utils.test.ts +++ b/code/addons/links/src/utils.test.ts @@ -32,8 +32,8 @@ describe('preview', () => { handler(); expect(channel.emit).toHaveBeenCalledWith(SELECT_STORY, { - kind: 'title', - story: 'name', + title: 'title', + name: 'name', }); }); @@ -42,7 +42,7 @@ describe('preview', () => { handler(); expect(channel.emit).toHaveBeenCalledWith(SELECT_STORY, { - kind: 'title', + title: 'title', }); }); @@ -53,7 +53,7 @@ describe('preview', () => { handler(); expect(channel.emit).toHaveBeenCalledWith(SELECT_STORY, { - story: 'name', + name: 'name', }); }); @@ -76,8 +76,8 @@ describe('preview', () => { expect(channel.emit.mock.calls).toContainEqual([ SELECT_STORY, { - kind: 'titlename', - story: 'nametitle', + title: 'titlename', + name: 'nametitle', }, ]); }); diff --git a/code/addons/links/src/utils.ts b/code/addons/links/src/utils.ts index e3836cc99364..041600e2b196 100644 --- a/code/addons/links/src/utils.ts +++ b/code/addons/links/src/utils.ts @@ -78,11 +78,11 @@ export const linkTo = if (title?.match(/--/) && !name) { navigate({ storyId: title }); } else if (name && title) { - navigate({ kind: title, story: name }); + navigate({ title, name }); } else if (title) { - navigate({ kind: title }); + navigate({ title }); } else if (name) { - navigate({ story: name }); + navigate({ name }); } }; @@ -92,10 +92,10 @@ const linksListener = (e: Event) => { return; } const element = target as HTMLElement; - const { sbKind: kind, sbStory: story } = element.dataset; - if (kind || story) { + const { sbKind, sbStory } = element.dataset; + if (sbKind || sbStory) { e.preventDefault(); - navigate({ kind, story }); + navigate({ title: sbKind, name: sbStory }); } }; diff --git a/code/core/src/manager-api/lib/stories.ts b/code/core/src/manager-api/lib/stories.ts index eb22188d1ee2..67a954c680f9 100644 --- a/code/core/src/manager-api/lib/stories.ts +++ b/code/core/src/manager-api/lib/stories.ts @@ -13,35 +13,22 @@ import type { DocsOptions, IndexEntry, Parameters, - SetStoriesPayload, - SetStoriesStoryData, StatusesByStoryIdAndTypeId, StoryId, StoryIndexV3, } from 'storybook/internal/types'; import { countBy } from 'es-toolkit/array'; -import { mapValues } from 'es-toolkit/object'; import memoize from 'memoizerific'; import { dedent } from 'ts-dedent'; import { Tag } from '../../shared/constants/tags.ts'; -import { type API, type State, combineParameters } from '../root.tsx'; +import { type API, type State } from '../root.tsx'; import intersect from './intersect.ts'; import merge from './merge.ts'; const TITLE_PATH_SEPARATOR = /\s*\/\s*/; -export const denormalizeStoryParameters = ({ - globalParameters, - stories, -}: SetStoriesPayload): SetStoriesStoryData => { - return mapValues(stories, (storyData) => ({ - ...storyData, - parameters: combineParameters(globalParameters, storyData.parameters as unknown as Parameters), - })) as SetStoriesStoryData; -}; - export const transformStoryIndexV3toV4 = (index: StoryIndexV3): API_PreparedStoryIndex => { const countByTitle = countBy(Object.values(index.stories), (item) => item.title); return { diff --git a/code/core/src/manager-api/modules/refs.ts b/code/core/src/manager-api/modules/refs.ts index 3c86f47551b4..8552af579e6d 100644 --- a/code/core/src/manager-api/modules/refs.ts +++ b/code/core/src/manager-api/modules/refs.ts @@ -322,7 +322,7 @@ export const init: ModuleFn = ( return refs; }, - setRef: async (id, { storyIndex, setStoriesData, ...rest }, ready = false) => { + setRef: async (id, { storyIndex, ...rest }, ready = false) => { if (singleStory) { return; } @@ -332,17 +332,15 @@ export const init: ModuleFn = ( const { filters } = store.getState(); const ref = api.getRefs()[id]; - if (storyIndex || setStoriesData) { + if (storyIndex) { internal_index = storyIndex; - // @ts-expect-error (could be undefined) filteredIndex = transformStoryIndexToStoriesHash(storyIndex, { provider, docsOptions, filters, allStatuses: {}, }); - // @ts-expect-error (could be undefined) index = transformStoryIndexToStoriesHash(storyIndex, { provider, docsOptions, diff --git a/code/core/src/manager-api/modules/stories.ts b/code/core/src/manager-api/modules/stories.ts index 35d8f403bfba..77ce64e407a0 100644 --- a/code/core/src/manager-api/modules/stories.ts +++ b/code/core/src/manager-api/modules/stories.ts @@ -10,7 +10,6 @@ import { SET_CURRENT_STORY, SET_FILTER, SET_INDEX, - SET_STORIES, SIDEBAR_FILTER_CHANGED, STORY_ARGS_UPDATED, STORY_CHANGED, @@ -36,13 +35,11 @@ import type { API_TestEntry, API_ViewMode, Args, - ComponentTitle, DocsPreparedPayload, - SetStoriesPayload, + SelectStoryPayload, StatusValue, StoryId, StoryIndex, - StoryName, StoryPreparedPayload, Tag, TagsOptions, @@ -57,7 +54,6 @@ import { countStatusesByValue } from '../../shared/status-store/index.ts'; import { getEventMetadata } from '../lib/events.ts'; import { addPreparedStories, - denormalizeStoryParameters, getComponentLookupList, getStoriesLookupList, transformStoryIndexToStoriesHash, @@ -771,8 +767,9 @@ export const init: ModuleFn = ({ // We can only do this if the stories.json is a proper storyIndex if (storyIndex.v < 3) { - logger.warn(`Skipping story index with version v${storyIndex.v}, awaiting SET_STORIES.`); - return; + throw new Error( + `Unsupported story index version: v${storyIndex.v}. Storybook 11 requires index version 3 or later.` + ); } await api.setIndex(storyIndex); @@ -1245,51 +1242,22 @@ export const init: ModuleFn = ({ } }); - // For composition back-compatibilty - provider.channel?.on(SET_STORIES, function handler(this: any, data: SetStoriesPayload) { + provider.channel?.on(SELECT_STORY, function handler(this: any, payload: SelectStoryPayload) { const { ref } = getEventMetadata(this, fullAPI)!; - const setStoriesData = data.v ? denormalizeStoryParameters(data) : data.stories; - if (!ref) { - throw new Error('Cannot call SET_STORIES for local frame'); + if ('storyId' in payload) { + const { storyId, viewMode, scrollTo } = payload; + fullAPI.selectStory(storyId, undefined, { viewMode, scrollTo, ref: ref?.id }); + } else if (payload.title || payload.name) { + const { title, name, viewMode, scrollTo } = payload; + fullAPI.selectStory(title, name, { viewMode, scrollTo, ref: ref?.id }); } else { - fullAPI.setRef(ref.id, { ...ref, setStoriesData }, true); + logger.warn( + 'Received a SELECT_STORY event without storyId or title; ignoring it. This can happen when a composed Storybook built with Storybook 10.x or earlier sends the legacy kind/story payload — see the 11.0.0 migration guide.' + ); } }); - provider.channel?.on( - SELECT_STORY, - function handler( - this: any, - { - title, - name, - storyId, - kind, - story, - ...rest - }: { - title?: ComponentTitle; - name?: StoryName; - storyId: string; - viewMode: API_ViewMode; - // Legacy pre-CSF3 spellings: dropped so they neither resolve nor leak into options. - /** @deprecated */ - kind?: unknown; - /** @deprecated */ - story?: unknown; - } - ) { - const { ref } = getEventMetadata(this, fullAPI)!; - - if (!ref) { - fullAPI.selectStory(storyId || title, name, rest); - } else { - fullAPI.selectStory(storyId || title, name, { ...rest, ref: ref.id }); - } - } - ); - provider.channel?.on( STORY_ARGS_UPDATED, function handleStoryArgsUpdated( diff --git a/code/core/src/manager-api/tests/stories.test.ts b/code/core/src/manager-api/tests/stories.test.ts index cee213b3592f..d5edccc20a7d 100644 --- a/code/core/src/manager-api/tests/stories.test.ts +++ b/code/core/src/manager-api/tests/stories.test.ts @@ -10,7 +10,6 @@ import { SET_CONFIG, SET_FILTER, SET_INDEX, - SET_STORIES, STORY_ARGS_UPDATED, STORY_INDEX_INVALIDATED, STORY_MISSING, @@ -1402,76 +1401,8 @@ describe('stories API', () => { }); }); }); - describe('v2 SET_STORIES event', () => { - it('normalizes parameters and calls setRef for external stories', () => { - const fullAPI = { - findRef: vi.fn(), - setRef: vi.fn(), - }; - const moduleArgs = createMockModuleArgs({ fullAPI }); - initStories(moduleArgs as unknown as ModuleArgs); - const { provider, store } = moduleArgs; - - getEventMetadata.mockReturnValueOnce({ - sourceType: 'external', - ref: { id: 'ref' }, - } as any); - const setStoriesPayload = { - v: 2, - globalParameters: { global: 'global' }, - kindParameters: { a: { kind: 'kind' } }, - stories: { 'a--1': { kind: 'a', parameters: { story: 'story' } } }, - }; - provider.channel.emit(SET_STORIES, setStoriesPayload); - expect(store.getState().index).toBeUndefined(); - expect(fullAPI.setRef).toHaveBeenCalledWith( - 'ref', - { - id: 'ref', - setStoriesData: { - 'a--1': { - kind: 'a', - parameters: { global: 'global', story: 'story' }, - }, - }, - }, - true - ); - }); - }); - describe('legacy (v1) SET_STORIES event', () => { - it('calls setRef with stories', () => { - const fullAPI = { - findRef: vi.fn(), - setRef: vi.fn(), - }; - const moduleArgs = createMockModuleArgs({ fullAPI }); - initStories(moduleArgs as unknown as ModuleArgs); - const { provider, store } = moduleArgs; - - getEventMetadata.mockReturnValueOnce({ - sourceType: 'external', - ref: { id: 'ref' }, - } as any); - const setStoriesPayload = { - stories: { 'a--1': {} }, - }; - provider.channel.emit(SET_STORIES, setStoriesPayload); - expect(store.getState().index).toBeUndefined(); - expect(fullAPI.setRef).toHaveBeenCalledWith( - 'ref', - { - id: 'ref', - setStoriesData: { - 'a--1': {}, - }, - }, - true - ); - }); - }); describe('SELECT_STORY event', () => { - it('resolves the story from title and name', () => { + const setup = () => { const fullAPI = { findRef: vi.fn(), setRef: vi.fn(), @@ -1479,7 +1410,11 @@ describe('stories API', () => { }; const moduleArgs = createMockModuleArgs({ fullAPI }); initStories(moduleArgs as unknown as ModuleArgs); - const { provider } = moduleArgs; + return { provider: moduleArgs.provider, fullAPI }; + }; + + it('resolves the story from title and name', () => { + const { provider, fullAPI } = setup(); getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); provider.channel.emit(SELECT_STORY, { @@ -1494,14 +1429,7 @@ describe('stories API', () => { }); it('resolves the story from storyId when provided', () => { - const fullAPI = { - findRef: vi.fn(), - setRef: vi.fn(), - selectStory: vi.fn(), - }; - const moduleArgs = createMockModuleArgs({ fullAPI }); - initStories(moduleArgs as unknown as ModuleArgs); - const { provider } = moduleArgs; + const { provider, fullAPI } = setup(); getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); provider.channel.emit(SELECT_STORY, { @@ -1514,15 +1442,9 @@ describe('stories API', () => { }); }); - it('does not fall back to the legacy kind/story payload fields', () => { - const fullAPI = { - findRef: vi.fn(), - setRef: vi.fn(), - selectStory: vi.fn(), - }; - const moduleArgs = createMockModuleArgs({ fullAPI }); - initStories(moduleArgs as unknown as ModuleArgs); - const { provider } = moduleArgs; + it('warns and does not navigate on the legacy kind/story payload', () => { + const { provider, fullAPI } = setup(); + const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); provider.channel.emit(SELECT_STORY, { @@ -1531,9 +1453,10 @@ describe('stories API', () => { viewMode: 'story', }); - expect(fullAPI.selectStory).toHaveBeenCalledWith(undefined, undefined, { - viewMode: 'story', - }); + expect(fullAPI.selectStory).not.toHaveBeenCalled(); + expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('without storyId or title')); + + warnSpy.mockRestore(); }); }); diff --git a/code/core/src/types/modules/api.ts b/code/core/src/types/modules/api.ts index d913fc536a00..ce766bf56cfb 100644 --- a/code/core/src/types/modules/api.ts +++ b/code/core/src/types/modules/api.ts @@ -12,7 +12,6 @@ import type { API_PreparedIndexEntry, API_RefStoryRuntimeData, } from './api-stories.ts'; -import type { SetStoriesStory, SetStoriesStoryData } from './channelApi.ts'; import type { DocsOptions } from './core-common.ts'; import type { StoryIndex } from './indexer.ts'; @@ -50,7 +49,6 @@ export interface API_Provider { sidebar?: API_SidebarOptions; theme?: ThemeVars; selectedPanel?: string; - StoryMapper?: API_StoryMapper; [k: string]: any; }; [key: string]: any; @@ -161,13 +159,10 @@ type API_Versions = Record; export type API_SetRefData = Partial< API_ComposedRef & { - setStoriesData: SetStoriesStoryData; storyIndex: StoryIndex; } >; -export type API_StoryMapper = (ref: API_ComposedRef, story: SetStoriesStory) => SetStoriesStory; - export interface API_LoadedRefData { index?: API_IndexHash; filteredIndex?: API_IndexHash; diff --git a/code/core/src/types/modules/channelApi.ts b/code/core/src/types/modules/channelApi.ts index b8e30448f8ad..4227a79fdadb 100644 --- a/code/core/src/types/modules/channelApi.ts +++ b/code/core/src/types/modules/channelApi.ts @@ -2,52 +2,18 @@ import type { API_ViewMode } from './api.ts'; import type { ArgTypes, Args, - ComponentId, + ComponentTitle, GlobalTypes, Globals, Parameters, StoryId, + StoryName, } from './csf.ts'; -// The data received on the (legacy) `setStories` event -export interface SetStoriesStory { - id: StoryId; - name: string; - refId?: string; - componentId?: ComponentId; - parameters: { - fileName: string; - options: { - [optionName: string]: any; - }; - docsOnly?: boolean; - viewMode?: API_ViewMode; - [parameterName: string]: any; - }; - argTypes?: ArgTypes; - args?: Args; - initialArgs?: Args; -} - -export interface SetStoriesStoryData { - [id: string]: SetStoriesStory; -} - -export type SetStoriesPayload = - | { - v: 2; - error?: Error; - globals: Args; - globalParameters: Parameters; - stories: SetStoriesStoryData; - kindParameters: { - [kind: string]: Parameters; - }; - } - | ({ - v?: number; - stories: SetStoriesStoryData; - } & Record); +export type SelectStoryPayload = + | { storyId: StoryId; viewMode?: API_ViewMode; scrollTo?: string } + // `title` is optional so a bare `name` can target the current component's story. + | { title?: ComponentTitle; name?: StoryName; viewMode?: API_ViewMode; scrollTo?: string }; export interface SetGlobalsPayload { // userGlobals diff --git a/code/core/src/types/modules/indexer.ts b/code/core/src/types/modules/indexer.ts index 6150fa6c2ae4..548eca5bdb26 100644 --- a/code/core/src/types/modules/indexer.ts +++ b/code/core/src/types/modules/indexer.ts @@ -166,16 +166,6 @@ export interface V3CompatIndexEntry extends Omit & { - name?: StoryName; - } - >; -} - export interface StoryIndexV3 { v: number; stories: Record; From 404c89c18da8315fb8639c2f696bcc3bd399381e Mon Sep 17 00:00:00 2001 From: Obvious Date: Thu, 15 Oct 2026 12:31:31 +0000 Subject: [PATCH 5/8] refactor(addon-links): adopt SelectStoryPayload and drop deprecated LinkTo props - Type navigate() with SelectStoryPayload and remove ParamsId/ParamsCombo. - Remove LinkTo's deprecated kind/story props; the data-sb-* attributes are unchanged. - Document the additional removals in MIGRATION.md and fix the table/wording. - Revert gratuitous line re-wraps flagged in review. --- MIGRATION.md | 28 +++++++++++-------- .../links/src/react/components/link.tsx | 19 ++++--------- code/addons/links/src/utils.ts | 14 ++-------- code/core/src/csf/story.ts | 9 ++---- .../src/manager-api/tests/stories.test.ts | 8 ++---- .../src/manager/components/sidebar/types.ts | 10 ++----- .../modules/preview-web/render/StoryRender.ts | 4 +-- .../modules/store/decorators.test.ts | 12 ++------ 8 files changed, 33 insertions(+), 71 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index aaef009e1ccf..ba35c51c0061 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -948,21 +948,25 @@ Decorators and `render` functions keep receiving `argTypes`, because renderers r ### Deprecated CSF and manager type aliases removed -Six deprecated type aliases from earlier Storybook versions are removed. If your code imports any of them from `storybook` (via `storybook/internal/csf`, `storybook/internal/types`, or `storybook/manager-api`), switch to the supported replacement: - -| Deprecated | Replacement | -| ----------------------- | ----------------------- | -| `StoryKind` | `ComponentTitle` | -| `StoryIdentifier.kind` | `StoryIdentifier.title` | -| `StoryIdentifier.story` | `StoryIdentifier.name` | -| `AnyFramework` | `Renderer` | -| `StoryContextForLoaders` | `StoryContext` | -| `PlayFunctionContext` | `StoryContext` | -| `StoriesHash` | `IndexHash` | +The following deprecated type aliases and fields are removed. If your code imports any of them from `storybook` (via `storybook/internal/csf`, `storybook/internal/types`, or `storybook/manager-api`), switch to the supported replacement: + +| Deprecated | Replacement | +| ------------------------ | ----------------------- | +| `StoryKind` | `ComponentTitle` | +| `StoryIdentifier.kind` | `StoryIdentifier.title` | +| `StoryIdentifier.story` | `StoryIdentifier.name` | +| `AnyFramework` | `Renderer` | +| `StoryContextForLoaders` | `StoryContext` | +| `PlayFunctionContext` | `StoryContext` | +| `StoriesHash` | `IndexHash` | + +The deprecated `kind` and `story` fields are also gone from `Addon_AddStoryArgs`, `Addon_StoryApi`, and the legacy `setStories` payload type `SetStoriesStory` (the whole interface is removed). The `RenderContext` passed to `renderToCanvas` no longer contains `kind` or `story`; third-party renderers read `title` and `name` instead. + +`@storybook/addon-links`' deprecated `LinkTo` `kind` and `story` props are removed; use `title` and `name`. The `data-sb-kind` and `data-sb-story` HTML attributes are unchanged. The provider `StoryMapper` option is removed. Story context objects passed to loaders and play functions no longer carry the deprecated `kind` and `story` keys; read `title` and `name` instead. The same applies to the context passed to decorators and `render` functions: custom helpers that read `context.kind` or `context.story` must switch to `context.title` and `context.name`. -The manager no longer accepts the pre-Storybook 3 wire format either: `SELECT_STORY` payloads are resolved from `storyId` or `title`/`name` only, and composed refs must publish a story index (`stories.json`) instead of a legacy `setStories` payload. +The manager resolves `SELECT_STORY` payloads from `storyId` or `title`/`name` only — the shape the event has used since Storybook 3. A payload without any of them is ignored with a warning, so cross-story links from composed Storybooks built with Storybook 10.x or earlier no longer navigate. Composed refs must publish a story index (`stories.json`); the v2 format is no longer accepted and the legacy `setStories` event is no longer read. ### `docgenServer` is stable and enabled by default diff --git a/code/addons/links/src/react/components/link.tsx b/code/addons/links/src/react/components/link.tsx index 837b720f60c3..e86aec6a16c1 100644 --- a/code/addons/links/src/react/components/link.tsx +++ b/code/addons/links/src/react/components/link.tsx @@ -22,9 +22,7 @@ const cancelled = (e: MouseEvent, cb = (_e: any) => {}) => { }; interface Props { - kind?: ComponentTitle; title?: ComponentTitle; - story?: StoryName; name?: StoryName; children: ReactNode; } @@ -47,20 +45,15 @@ export default class LinkTo extends PureComponent { } componentDidUpdate(prevProps: Props) { - const { kind, title, story, name } = this.props; - - if ( - prevProps.kind !== kind || - prevProps.story !== story || - prevProps.title !== title || - prevProps.name !== name - ) { + const { title, name } = this.props; + + if (prevProps.title !== title || prevProps.name !== name) { this.updateHref(); } } updateHref = async () => { - const { kind, title = kind, story, name = story } = this.props; + const { title, name } = this.props; if (title && name) { const href = await hrefTo(title, name); this.setState({ href }); @@ -68,14 +61,14 @@ export default class LinkTo extends PureComponent { }; handleClick = () => { - const { kind, title = kind, story, name = story } = this.props; + const { title, name } = this.props; if (title && name) { navigate({ title, name }); } }; render() { - const { kind, title = kind, story, name = story, children, ...rest } = this.props; + const { title, name, children, ...rest } = this.props; const { href } = this.state; return ( diff --git a/code/addons/links/src/utils.ts b/code/addons/links/src/utils.ts index 041600e2b196..6b455b535c69 100644 --- a/code/addons/links/src/utils.ts +++ b/code/addons/links/src/utils.ts @@ -1,6 +1,6 @@ import { SELECT_STORY, STORY_CHANGED } from 'storybook/internal/core-events'; import { toId } from 'storybook/internal/csf'; -import type { ComponentTitle, StoryId, StoryName } from 'storybook/internal/types'; +import type { ComponentTitle, SelectStoryPayload, StoryName } from 'storybook/internal/types'; import { global } from '@storybook/global'; @@ -10,16 +10,6 @@ import { PARAM_KEY } from './constants.ts'; const { document, HTMLElement } = global; -interface ParamsId { - storyId: StoryId; -} -interface ParamsCombo { - kind?: ComponentTitle; - title?: ComponentTitle; - story?: StoryName; - name?: StoryName; -} - function parseQuery(queryString: string) { const query: Record = {}; const pairs = (queryString[0] === '?' ? queryString.substring(1) : queryString) @@ -33,7 +23,7 @@ function parseQuery(queryString: string) { return query; } -export const navigate = (params: ParamsId | ParamsCombo) => +export const navigate = (params: SelectStoryPayload) => addons.getChannel().emit(SELECT_STORY, params); const generateStoryUrl = (title: ComponentTitle | undefined, name: StoryName): string => { diff --git a/code/core/src/csf/story.ts b/code/core/src/csf/story.ts index 6d829f7a37cc..92632b02d7a3 100644 --- a/code/core/src/csf/story.ts +++ b/code/core/src/csf/story.ts @@ -123,10 +123,7 @@ export interface InputType { /** @see https://storybook.js.org/docs/api/arg-types#tablecategory */ category?: string; /** @see https://storybook.js.org/docs/api/arg-types#tabledefaultvalue */ - defaultValue?: { - summary?: string | undefined; - detail?: string | undefined; - }; + defaultValue?: { summary?: string | undefined; detail?: string | undefined }; /** @see https://storybook.js.org/docs/api/arg-types#tabledisable */ disable?: boolean; /** @see https://storybook.js.org/docs/api/arg-types#tablesubcategory */ @@ -159,9 +156,7 @@ export interface StrictArgs { /** @see https://storybook.js.org/docs/api/arg-types#argtypes */ export type ArgTypes = { [name in keyof TArgs]: InputType }; -export type StrictArgTypes = { - [name in keyof TArgs]: StrictInputType; -}; +export type StrictArgTypes = { [name in keyof TArgs]: StrictInputType }; export interface Globals { [name: string]: any; diff --git a/code/core/src/manager-api/tests/stories.test.ts b/code/core/src/manager-api/tests/stories.test.ts index d5edccc20a7d..5dc2db465f07 100644 --- a/code/core/src/manager-api/tests/stories.test.ts +++ b/code/core/src/manager-api/tests/stories.test.ts @@ -1423,9 +1423,7 @@ describe('stories API', () => { viewMode: 'story', }); - expect(fullAPI.selectStory).toHaveBeenCalledWith('a', '1', { - viewMode: 'story', - }); + expect(fullAPI.selectStory).toHaveBeenCalledWith('a', '1', { viewMode: 'story' }); }); it('resolves the story from storyId when provided', () => { @@ -1437,9 +1435,7 @@ describe('stories API', () => { viewMode: 'story', }); - expect(fullAPI.selectStory).toHaveBeenCalledWith('a--1', undefined, { - viewMode: 'story', - }); + expect(fullAPI.selectStory).toHaveBeenCalledWith('a--1', undefined, { viewMode: 'story' }); }); it('warns and does not navigate on the legacy kind/story payload', () => { diff --git a/code/core/src/manager/components/sidebar/types.ts b/code/core/src/manager/components/sidebar/types.ts index e1a1c900f773..331c99dbb74c 100644 --- a/code/core/src/manager/components/sidebar/types.ts +++ b/code/core/src/manager/components/sidebar/types.ts @@ -4,9 +4,7 @@ import type { ControllerStateAndHelpers } from 'downshift'; import type { IndexHash, State } from 'storybook/manager-api'; export type Refs = State['refs']; -export type RefType = Refs[keyof Refs] & { - allStatuses?: StatusesByStoryIdAndTypeId; -}; +export type RefType = Refs[keyof Refs] & { allStatuses?: StatusesByStoryIdAndTypeId }; export type Item = IndexHash[keyof IndexHash]; export type Dataset = Record; @@ -47,11 +45,7 @@ export interface ExpandType { moreCount: number; } -export type SearchItem = Item & { - refId: string; - path: string[]; - status?: StatusValue; -}; +export type SearchItem = Item & { refId: string; path: string[]; status?: StatusValue }; export type SearchResult = Fuse.FuseResultWithMatches & Fuse.FuseResultWithScore; diff --git a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts index e99be5231b04..ff0d28383ec6 100644 --- a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts +++ b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts @@ -84,9 +84,7 @@ export class StoryRender implements Render, private renderToScreen: RenderToCanvas, - private callbacks: RenderContextCallbacks & { - showStoryDuringRender?: () => void; - }, + private callbacks: RenderContextCallbacks & { showStoryDuringRender?: () => void }, public id: StoryId, public viewMode: StoryContext['viewMode'], public renderOptions: StoryRenderOptions = { autoplay: true, forceInitialArgs: false }, diff --git a/code/core/src/preview-api/modules/store/decorators.test.ts b/code/core/src/preview-api/modules/store/decorators.test.ts index 892147ad94d5..0edfa647d922 100644 --- a/code/core/src/preview-api/modules/store/decorators.test.ts +++ b/code/core/src/preview-api/modules/store/decorators.test.ts @@ -128,16 +128,8 @@ describe('client-api.decorators', () => { expect(contexts).toEqual([]); decorated(makeContext({ parameters: { a: 'b' } })); expect(contexts).toEqual([ - expect.objectContaining({ - parameters: { a: 'b' }, - id: 'id', - name: 'name', - }), - expect.objectContaining({ - parameters: { a: 'b' }, - id: 'id', - name: 'name', - }), + expect.objectContaining({ parameters: { a: 'b' }, id: 'id', name: 'name' }), + expect.objectContaining({ parameters: { a: 'b' }, id: 'id', name: 'name' }), ]); }); }); From e673239bcd8a8f1136e40b2b90e5c2c5c3ed7acd Mon Sep 17 00:00:00 2001 From: Obvious Date: Thu, 15 Oct 2026 22:27:31 +0000 Subject: [PATCH 6/8] fix(core): restore extract() legacy fields and legacy SELECT_STORY navigation StoryStore.extract() keeps the deprecated kind/story keys on its output for external extractors such as the Chromatic CLI, via a named ExtractedStory return type; prepared story context types stay free of them. The SELECT_STORY receiver normalizes legacy kind/story payloads from composed Storybooks built with 10.x or earlier so cross-story links in those refs keep navigating, and warns only on payloads without any story identifier. The story-index v2 rejection now lives in transformStoryIndexToStoriesHash so local and composed indexes share one check. MIGRATION.md and the addon-links README document the supported behavior. --- MIGRATION.md | 4 +- code/addons/links/README.md | 13 +++-- code/core/src/manager-api/lib/stories.ts | 5 ++ code/core/src/manager-api/modules/stories.ts | 44 ++++++++++++----- .../src/manager-api/tests/stories.test.ts | 21 ++++++-- .../modules/preview-web/PreviewWeb.test.ts | 8 ++++ .../modules/store/StoryStore.test.ts | 48 +++++++++++++++++++ .../preview-api/modules/store/StoryStore.ts | 21 ++++++-- 8 files changed, 137 insertions(+), 27 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index ba35c51c0061..58156302624b 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -964,9 +964,9 @@ The deprecated `kind` and `story` fields are also gone from `Addon_AddStoryArgs` `@storybook/addon-links`' deprecated `LinkTo` `kind` and `story` props are removed; use `title` and `name`. The `data-sb-kind` and `data-sb-story` HTML attributes are unchanged. The provider `StoryMapper` option is removed. -Story context objects passed to loaders and play functions no longer carry the deprecated `kind` and `story` keys; read `title` and `name` instead. The same applies to the context passed to decorators and `render` functions: custom helpers that read `context.kind` or `context.story` must switch to `context.title` and `context.name`. +Story context objects passed to loaders and play functions no longer carry the deprecated `kind` and `story` keys; read `title` and `name` instead. The same applies to the context passed to decorators and `render` functions: custom helpers that read `context.kind` or `context.story` must switch to `context.title` and `context.name`. The `extract()` output — the serialized stories that external tools such as the Chromatic CLI read — still includes the deprecated `kind` and `story` fields for compatibility, so tools reading the serialized output keep working. -The manager resolves `SELECT_STORY` payloads from `storyId` or `title`/`name` only — the shape the event has used since Storybook 3. A payload without any of them is ignored with a warning, so cross-story links from composed Storybooks built with Storybook 10.x or earlier no longer navigate. Composed refs must publish a story index (`stories.json`); the v2 format is no longer accepted and the legacy `setStories` event is no longer read. +The manager resolves `SELECT_STORY` payloads from `storyId` or `title`/`name`, and still accepts the deprecated `kind`/`story` payload that composed Storybooks built with Storybook 10.x or earlier send, so cross-story links inside those refs keep navigating. A payload without any of those keys is ignored with a warning. Composed refs must publish a story index (`stories.json`); the v2 format is no longer accepted and the legacy `setStories` event is no longer read. ### `docgenServer` is stable and enabled by default diff --git a/code/addons/links/README.md b/code/addons/links/README.md index 0192e4d55e5c..c4c7d1c22671 100644 --- a/code/addons/links/README.md +++ b/code/addons/links/README.md @@ -70,9 +70,9 @@ export const index = () => ( ); -export const first = () => Go back; -export const second = () => Go back; -export const third = () => Go back; +export const first = () => Go back; +export const second = () => Go back; +export const third = () => Go back; ``` ## hrefTo function @@ -145,14 +145,13 @@ export const first = () => Go to Second; export const second = () => Go to First; ``` -It accepts all the props the `a` element does, plus `story` and `kind`. It the `kind` prop is omitted, the current kind will be preserved. +It accepts all the props the `a` element does, plus `title` and `name`. If the `title` prop is omitted, the current component's title will be used. ```mdx Go to Second diff --git a/code/core/src/manager-api/lib/stories.ts b/code/core/src/manager-api/lib/stories.ts index 67a954c680f9..7c1f461786f2 100644 --- a/code/core/src/manager-api/lib/stories.ts +++ b/code/core/src/manager-api/lib/stories.ts @@ -100,6 +100,11 @@ export const transformStoryIndexToStoriesHash = ( if (!input.v) { throw new Error('Composition: Missing stories.json version'); } + if (input.v < 3) { + throw new Error( + `Unsupported story index version: v${input.v}. Storybook 11 requires index version 3 or later.` + ); + } let index = input; index = index.v === 3 ? transformStoryIndexV3toV4(index as any) : index; diff --git a/code/core/src/manager-api/modules/stories.ts b/code/core/src/manager-api/modules/stories.ts index 77ce64e407a0..606ae65b8d93 100644 --- a/code/core/src/manager-api/modules/stories.ts +++ b/code/core/src/manager-api/modules/stories.ts @@ -35,11 +35,13 @@ import type { API_TestEntry, API_ViewMode, Args, + ComponentTitle, DocsPreparedPayload, SelectStoryPayload, StatusValue, StoryId, StoryIndex, + StoryName, StoryPreparedPayload, Tag, TagsOptions, @@ -71,6 +73,34 @@ import { serializeTagsParam, } from './tags.ts'; +/** Sent by composed Storybooks built with 10.x or earlier (their addon-links). */ +type LegacySelectStoryPayload = { + /** @deprecated Use `title`. */ + kind?: ComponentTitle; + /** @deprecated Use `name`. */ + story?: StoryName; + viewMode?: API_ViewMode; + scrollTo?: string; +}; + +/** + * Accepts the deprecated `kind`/`story` keys so cross-story links inside composed + * Storybooks built with 10.x or earlier keep navigating; everything downstream is modern-only. + */ +type SelectStoryEvent = SelectStoryPayload | LegacySelectStoryPayload; + +const normalizeSelectStoryPayload = (payload: SelectStoryEvent): SelectStoryPayload => { + if ('storyId' in payload) { + return payload; + } + const { viewMode, scrollTo } = payload; + const title = + ('title' in payload && payload.title) || ('kind' in payload ? payload.kind : undefined); + const name = + ('name' in payload && payload.name) || ('story' in payload ? payload.story : undefined); + return { title, name, viewMode, scrollTo }; +}; + const { fetch } = global; const STORY_INDEX_PATH = './index.json'; @@ -765,13 +795,6 @@ export const init: ModuleFn = ({ const storyIndex = (await result.json()) as StoryIndex; - // We can only do this if the stories.json is a proper storyIndex - if (storyIndex.v < 3) { - throw new Error( - `Unsupported story index version: v${storyIndex.v}. Storybook 11 requires index version 3 or later.` - ); - } - await api.setIndex(storyIndex); } catch (err: any) { await store.setState({ indexError: err }); @@ -1242,8 +1265,9 @@ export const init: ModuleFn = ({ } }); - provider.channel?.on(SELECT_STORY, function handler(this: any, payload: SelectStoryPayload) { + provider.channel?.on(SELECT_STORY, function handler(this: any, rawPayload: SelectStoryEvent) { const { ref } = getEventMetadata(this, fullAPI)!; + const payload = normalizeSelectStoryPayload(rawPayload); if ('storyId' in payload) { const { storyId, viewMode, scrollTo } = payload; @@ -1252,9 +1276,7 @@ export const init: ModuleFn = ({ const { title, name, viewMode, scrollTo } = payload; fullAPI.selectStory(title, name, { viewMode, scrollTo, ref: ref?.id }); } else { - logger.warn( - 'Received a SELECT_STORY event without storyId or title; ignoring it. This can happen when a composed Storybook built with Storybook 10.x or earlier sends the legacy kind/story payload — see the 11.0.0 migration guide.' - ); + logger.warn('Received a SELECT_STORY event without storyId or title; ignoring it.'); } }); diff --git a/code/core/src/manager-api/tests/stories.test.ts b/code/core/src/manager-api/tests/stories.test.ts index 5dc2db465f07..bac0202d7d9a 100644 --- a/code/core/src/manager-api/tests/stories.test.ts +++ b/code/core/src/manager-api/tests/stories.test.ts @@ -1438,17 +1438,32 @@ describe('stories API', () => { expect(fullAPI.selectStory).toHaveBeenCalledWith('a--1', undefined, { viewMode: 'story' }); }); - it('warns and does not navigate on the legacy kind/story payload', () => { + it('resolves the story from the legacy kind/story payload sent by older composed Storybooks', () => { const { provider, fullAPI } = setup(); - const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); - getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); + getEventMetadata.mockReturnValueOnce({ + sourceType: 'external', + ref: { id: 'ref' }, + } as any); provider.channel.emit(SELECT_STORY, { kind: 'a', story: '1', viewMode: 'story', }); + expect(fullAPI.selectStory).toHaveBeenCalledWith('a', '1', { + viewMode: 'story', + ref: 'ref', + }); + }); + + it('warns and does not navigate on a payload without storyId or title', () => { + const { provider, fullAPI } = setup(); + const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); + + getEventMetadata.mockReturnValueOnce({ sourceType: 'local' } as any); + provider.channel.emit(SELECT_STORY, {}); + expect(fullAPI.selectStory).not.toHaveBeenCalled(); expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('without storyId or title')); diff --git a/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts b/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts index 0501cb0f37ba..01712a252b53 100644 --- a/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts +++ b/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts @@ -3919,6 +3919,7 @@ describe('PreviewWeb', () => { "foo": "a", "one": 1, }, + "kind": "Component One", "name": "A", "parameters": { "__isArgsStory": false, @@ -3938,6 +3939,7 @@ describe('PreviewWeb', () => { "fileName": "./src/ComponentOne.stories.js", "throwPlayFunctionExceptions": false, }, + "story": "A", "storyGlobals": {}, "storyId": "component-one--a", "subcomponents": undefined, @@ -3991,6 +3993,7 @@ describe('PreviewWeb', () => { "foo": "b", "one": 1, }, + "kind": "Component One", "name": "B", "parameters": { "__isArgsStory": false, @@ -4010,6 +4013,7 @@ describe('PreviewWeb', () => { "fileName": "./src/ComponentOne.stories.js", "throwPlayFunctionExceptions": false, }, + "story": "B", "storyGlobals": {}, "storyId": "component-one--b", "subcomponents": undefined, @@ -4041,6 +4045,7 @@ describe('PreviewWeb', () => { }, "id": "component-one--e", "initialArgs": {}, + "kind": "Component One", "name": "E", "parameters": { "__isArgsStory": false, @@ -4060,6 +4065,7 @@ describe('PreviewWeb', () => { "throwPlayFunctionExceptions": false, }, "playFunction": undefined, + "story": "E", "storyGlobals": {}, "storyId": "component-one--e", "subcomponents": undefined, @@ -4102,6 +4108,7 @@ describe('PreviewWeb', () => { "initialArgs": { "foo": "c", }, + "kind": "Component Two", "name": "C", "parameters": { "__isArgsStory": false, @@ -4120,6 +4127,7 @@ describe('PreviewWeb', () => { "throwPlayFunctionExceptions": false, }, "playFunction": undefined, + "story": "C", "storyGlobals": {}, "storyId": "component-two--c", "subcomponents": undefined, diff --git a/code/core/src/preview-api/modules/store/StoryStore.test.ts b/code/core/src/preview-api/modules/store/StoryStore.test.ts index 4a33ab099dcf..a4e285286ea5 100644 --- a/code/core/src/preview-api/modules/store/StoryStore.test.ts +++ b/code/core/src/preview-api/modules/store/StoryStore.test.ts @@ -379,6 +379,7 @@ describe('StoryStore', () => { "initialArgs": { "foo": "a", }, + "kind": "Component One", "name": "A", "parameters": { "__isArgsStory": false, @@ -395,6 +396,7 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, + "story": "A", "storyGlobals": {}, "storyId": "component-one--a", "subcomponents": undefined, @@ -575,6 +577,7 @@ describe('StoryStore', () => { "initialArgs": { "foo": "a", }, + "kind": "Component One", "name": "A", "parameters": { "__isArgsStory": false, @@ -591,6 +594,7 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, + "story": "A", "storyGlobals": {}, "storyId": "component-one--a", "subcomponents": undefined, @@ -640,6 +644,7 @@ describe('StoryStore', () => { "initialArgs": { "foo": "b", }, + "kind": "Component One", "name": "B", "parameters": { "__isArgsStory": false, @@ -656,6 +661,7 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, + "story": "B", "storyGlobals": {}, "storyId": "component-one--b", "subcomponents": undefined, @@ -704,6 +710,7 @@ describe('StoryStore', () => { "initialArgs": { "foo": "c", }, + "kind": "Component Two", "name": "C", "parameters": { "__isArgsStory": false, @@ -720,6 +727,7 @@ describe('StoryStore', () => { }, "playFunction": undefined, "renderToCanvas": undefined, + "story": "C", "storyGlobals": {}, "storyId": "component-two--c", "subcomponents": undefined, @@ -735,6 +743,46 @@ describe('StoryStore', () => { `); }); + it('sets story to the parent story name for test entries and keeps the deprecated kind field', async () => { + const testExports = { + default: { title: 'Component One' }, + a: { args: { foo: 'a' } }, + 'a--test': { args: { foo: 'a' } }, + }; + const testImportFn = vi.fn(async (path) => + path === './src/ComponentOne.stories.js' ? testExports : componentTwoExports + ); + const testIndex: StoryIndex = { + v: 5, + entries: { + 'component-one--a': { + type: 'story', + subtype: 'story', + id: 'component-one--a', + title: 'Component One', + name: 'A', + importPath: './src/ComponentOne.stories.js', + }, + 'component-one--a--test': { + type: 'story', + subtype: 'test', + id: 'component-one--a--test', + title: 'Component One', + name: 'A Test', + parent: 'component-one--a', + parentName: 'A', + importPath: './src/ComponentOne.stories.js', + }, + }, + }; + const store = new StoryStore(testIndex, testImportFn, projectAnnotations); + await store.cacheAllCSFFiles(); + + const extracted = store.extract(); + expect(extracted['component-one--a--test'].story).toBe('A'); + expect(extracted['component-one--a--test'].kind).toBe('Component One'); + }); + it('does not include (legacy) docs only stories by default', async () => { const docsOnlyImportFn = vi.fn(async (path) => { return path === './src/ComponentOne.stories.js' diff --git a/code/core/src/preview-api/modules/store/StoryStore.ts b/code/core/src/preview-api/modules/store/StoryStore.ts index 3f5aeeb08475..aed7c40fff49 100644 --- a/code/core/src/preview-api/modules/store/StoryStore.ts +++ b/code/core/src/preview-api/modules/store/StoryStore.ts @@ -4,6 +4,7 @@ import { MissingStoryFromCsfFileError, } from 'storybook/internal/preview-errors'; import type { + ComponentTitle, CSFFile, IndexEntry, ModuleExports, @@ -17,6 +18,7 @@ import type { StoryContextForEnhancers, StoryId, StoryIndex, + StoryName, } from 'storybook/internal/types'; import { omitBy, pick } from 'es-toolkit/object'; @@ -57,6 +59,18 @@ function composeProjectAnnotations( const CSF_CACHE_SIZE = 1000; const STORY_CACHE_SIZE = 10000; +/** + * The serialized story an external tool (such as the Chromatic CLI) reads via `extract()`. + * Keeps the deprecated `kind`/`story` fields for those extractors; everything else uses `title`/`name`. + */ +export type ExtractedStory = + StoryContextForEnhancers & { + /** @deprecated Use `title`. Kept for external extractors such as the Chromatic CLI. */ + kind: ComponentTitle; + /** @deprecated Use `name`. Kept for external extractors such as the Chromatic CLI. */ + story: StoryName; + }; + export class StoryStore { public storyIndex: StoryIndexStore; @@ -292,7 +306,7 @@ export class StoryStore { extract( options: { includeDocsOnly?: boolean } = { includeDocsOnly: false } - ): Record> { + ): Record> { const { cachedCSFFiles } = this; console.log('extract: extracting stories', cachedCSFFiles); @@ -316,9 +330,6 @@ export class StoryStore { acc[storyId] = Object.entries(story).reduce( (storyAcc, [key, value]) => { - if (key === 'story' && entry.subtype === 'test') { - return { ...storyAcc, story: entry.parentName }; - } if (key === 'moduleExport') { return storyAcc; } @@ -338,6 +349,8 @@ export class StoryStore { ...story.storyGlobals, }, storyId: entry.parent ? entry.parent : storyId, + kind: story.title, + story: entry.subtype === 'test' ? entry.parentName : story.name, } ); return acc; From 5c5c2a31bdb90cbc95eb3eefa3cbeefce4e07a65 Mon Sep 17 00:00:00 2001 From: Obvious Date: Thu, 15 Oct 2026 22:32:44 +0000 Subject: [PATCH 7/8] test(core): align the extract test-entry id with processCSFFile's derived id --- .../core/src/preview-api/modules/store/StoryStore.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/core/src/preview-api/modules/store/StoryStore.test.ts b/code/core/src/preview-api/modules/store/StoryStore.test.ts index a4e285286ea5..565d0bf721b1 100644 --- a/code/core/src/preview-api/modules/store/StoryStore.test.ts +++ b/code/core/src/preview-api/modules/store/StoryStore.test.ts @@ -763,10 +763,10 @@ describe('StoryStore', () => { name: 'A', importPath: './src/ComponentOne.stories.js', }, - 'component-one--a--test': { + 'component-one--a-test': { type: 'story', subtype: 'test', - id: 'component-one--a--test', + id: 'component-one--a-test', title: 'Component One', name: 'A Test', parent: 'component-one--a', @@ -779,8 +779,8 @@ describe('StoryStore', () => { await store.cacheAllCSFFiles(); const extracted = store.extract(); - expect(extracted['component-one--a--test'].story).toBe('A'); - expect(extracted['component-one--a--test'].kind).toBe('Component One'); + expect(extracted['component-one--a-test'].story).toBe('A'); + expect(extracted['component-one--a-test'].kind).toBe('Component One'); }); it('does not include (legacy) docs only stories by default', async () => { From 22d3664babf9b5119648633231c021b2d46e3b3b Mon Sep 17 00:00:00 2001 From: Obvious Date: Fri, 16 Oct 2026 17:56:01 +0000 Subject: [PATCH 8/8] refactor(core,addon-links): widen SELECT_STORY warning and use name= in README examples The ignore branch accepts a payload with only a name, so the warning now names all three accepted identifiers and the test checks the new wording. The last two LinkTo README examples still passed the removed story prop; they now use name= like the rest. --- code/addons/links/README.md | 4 ++-- code/core/src/manager-api/modules/stories.ts | 2 +- code/core/src/manager-api/tests/stories.test.ts | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/code/addons/links/README.md b/code/addons/links/README.md index c4c7d1c22671..75b5711d01ca 100644 --- a/code/addons/links/README.md +++ b/code/addons/links/README.md @@ -141,8 +141,8 @@ export default { title: 'Link', }; -export const first = () => Go to Second; -export const second = () => Go to First; +export const first = () => Go to Second; +export const second = () => Go to First; ``` It accepts all the props the `a` element does, plus `title` and `name`. If the `title` prop is omitted, the current component's title will be used. diff --git a/code/core/src/manager-api/modules/stories.ts b/code/core/src/manager-api/modules/stories.ts index 606ae65b8d93..9521105d13b8 100644 --- a/code/core/src/manager-api/modules/stories.ts +++ b/code/core/src/manager-api/modules/stories.ts @@ -1276,7 +1276,7 @@ export const init: ModuleFn = ({ const { title, name, viewMode, scrollTo } = payload; fullAPI.selectStory(title, name, { viewMode, scrollTo, ref: ref?.id }); } else { - logger.warn('Received a SELECT_STORY event without storyId or title; ignoring it.'); + logger.warn('Received a SELECT_STORY event without storyId, title or name; ignoring it.'); } }); diff --git a/code/core/src/manager-api/tests/stories.test.ts b/code/core/src/manager-api/tests/stories.test.ts index bac0202d7d9a..b71dfcf04f37 100644 --- a/code/core/src/manager-api/tests/stories.test.ts +++ b/code/core/src/manager-api/tests/stories.test.ts @@ -1457,7 +1457,7 @@ describe('stories API', () => { }); }); - it('warns and does not navigate on a payload without storyId or title', () => { + it('warns and does not navigate on a payload without storyId, title or name', () => { const { provider, fullAPI } = setup(); const warnSpy = vi.spyOn(logger, 'warn').mockImplementation(() => {}); @@ -1465,7 +1465,9 @@ describe('stories API', () => { provider.channel.emit(SELECT_STORY, {}); expect(fullAPI.selectStory).not.toHaveBeenCalled(); - expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('without storyId or title')); + expect(warnSpy).toHaveBeenCalledWith( + expect.stringContaining('without storyId, title or name') + ); warnSpy.mockRestore(); });