Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -946,6 +947,28 @@ 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

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 `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`, 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

The `experimentalDocgenServer` feature is now `docgenServer`, and Storybook no longer reads the old name.
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions code/addons/docs/src/blocks/blocks/ArgTypes.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Custom docs page: {@link ./ArgTypes.mdx} (attached via `<Meta of={...} />`). */
import type { PlayFunctionContext } from 'storybook/internal/csf';
import type { StoryContext } from 'storybook/internal/csf';

import type { Meta, StoryObj } from '@storybook/react-vite';

Expand Down Expand Up @@ -133,7 +133,7 @@ const DOCGEN_TIMEOUT = { timeout: 5000 };

const findSubcomponentTabs = async (
canvas: Parameters<NonNullable<Story['play']>>[0]['canvas'],
step: PlayFunctionContext['step']
step: StoryContext['step']
) => {
let subcomponentATab: HTMLElement | null = null;
let subcomponentBTab: HTMLElement | null = null;
Expand Down
4 changes: 2 additions & 2 deletions code/addons/docs/src/blocks/blocks/Controls.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Custom docs page: {@link ./Controls.mdx} (attached via `<Meta of={...} />`). */
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';

Expand Down Expand Up @@ -103,7 +103,7 @@ const DOCGEN_TIMEOUT = { timeout: 5000 };

const findSubcomponentTabs = async (
canvas: ReturnType<typeof within>,
step: PlayFunctionContext['step']
step: StoryContext['step']
) => {
let subcomponentATab: HTMLElement | null = null;
let subcomponentBTab: HTMLElement | null = null;
Expand Down
4 changes: 2 additions & 2 deletions code/addons/docs/src/blocks/components/Story.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<WebRenderer>) => {
play: async ({ args, canvasElement, loaded }: StoryContext<WebRenderer>) => {
const docsContext = loaded.docsContext as DocsContextProps;
const resolved = docsContext.resolveOf(args.storyExport, ['story']);

Expand Down
13 changes: 6 additions & 7 deletions code/addons/links/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export const index = () => (
<option>third</option>
</select>
);
export const first = () => <LinkTo story="index">Go back</LinkTo>;
export const second = () => <LinkTo story="index">Go back</LinkTo>;
export const third = () => <LinkTo story="index">Go back</LinkTo>;
export const first = () => <LinkTo name="index">Go back</LinkTo>;
export const second = () => <LinkTo name="index">Go back</LinkTo>;
export const third = () => <LinkTo name="index">Go back</LinkTo>;
```

## hrefTo function
Expand Down Expand Up @@ -145,14 +145,13 @@ export const first = () => <LinkTo story="second">Go to Second</LinkTo>;
export const second = () => <LinkTo story="first">Go to First</LinkTo>;
Comment thread
valentinpalkovic marked this conversation as resolved.
Resolved
```

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
<LinkTo
kind="Toggle"
story="off"
title="Toggle"
name="off"
target="_blank"
title="link to second story"
style={{ color: '#1474f3' }}
>
Go to Second
Expand Down
21 changes: 7 additions & 14 deletions code/addons/links/src/react/components/link.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -22,9 +22,7 @@ const cancelled = (e: MouseEvent<HTMLAnchorElement>, cb = (_e: any) => {}) => {
};

interface Props {
Comment thread
valentinpalkovic marked this conversation as resolved.
Resolved
kind?: StoryKind;
title?: ComponentTitle;
story?: StoryName;
name?: StoryName;
children: ReactNode;
}
Expand All @@ -47,35 +45,30 @@ export default class LinkTo extends PureComponent<Props, State> {
}

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 });
}
};

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 (
Expand Down
12 changes: 6 additions & 6 deletions code/addons/links/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('preview', () => {
handler();

expect(channel.emit).toHaveBeenCalledWith(SELECT_STORY, {
kind: 'title',
story: 'name',
title: 'title',
name: 'name',
});
});

Expand All @@ -42,7 +42,7 @@ describe('preview', () => {
handler();

expect(channel.emit).toHaveBeenCalledWith(SELECT_STORY, {
kind: 'title',
title: 'title',
});
});

Expand All @@ -53,7 +53,7 @@ describe('preview', () => {
handler();

expect(channel.emit).toHaveBeenCalledWith(SELECT_STORY, {
story: 'name',
name: 'name',
});
});

Expand All @@ -76,8 +76,8 @@ describe('preview', () => {
expect(channel.emit.mock.calls).toContainEqual([
SELECT_STORY,
{
kind: 'titlename',
story: 'nametitle',
title: 'titlename',
name: 'nametitle',
},
]);
});
Expand Down
26 changes: 8 additions & 18 deletions code/addons/links/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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, SelectStoryPayload, StoryName } from 'storybook/internal/types';

import { global } from '@storybook/global';

Expand All @@ -10,16 +10,6 @@ import { PARAM_KEY } from './constants.ts';

const { document, HTMLElement } = global;

interface ParamsId {
storyId: StoryId;
}
interface ParamsCombo {
kind?: StoryKind;
title?: ComponentTitle;
story?: StoryName;
name?: StoryName;
}

function parseQuery(queryString: string) {
const query: Record<string, string> = {};
const pairs = (queryString[0] === '?' ? queryString.substring(1) : queryString)
Expand All @@ -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 => {
Expand Down Expand Up @@ -78,11 +68,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 });
}
};

Expand All @@ -92,10 +82,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 });
}
};

Expand Down
26 changes: 2 additions & 24 deletions code/core/src/csf/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
Expand Down Expand Up @@ -217,9 +210,6 @@ export interface Renderer extends AddonTypes {
csf4: boolean;
}

/** @deprecated - Use `Renderer` */
export type AnyFramework = Renderer;

export interface StoryContextForEnhancers<
TRenderer extends Renderer = Renderer,
TArgs = Args,
Expand Down Expand Up @@ -251,7 +241,7 @@ export interface StoryContextUpdate<TArgs = Args> {
export type ViewMode = 'story' | 'docs';

export type LoaderFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (
context: StoryContextForLoaders<TRenderer, TArgs>
context: StoryContext<TRenderer, TArgs>
) => Promise<Record<string, any> | void> | Record<string, any> | void;

type Awaitable<T> = T | PromiseLike<T>;
Expand Down Expand Up @@ -306,18 +296,6 @@ export interface StoryContextForRender<
argTypes: StrictArgTypes<TArgs>;
}

/** @deprecated Use {@link StoryContext} instead. */
export interface StoryContextForLoaders<
TRenderer extends Renderer = Renderer,
TArgs = Args,
> extends StoryContext<TRenderer, TArgs> {}

/** @deprecated Use {@link StoryContext} instead. */
export interface PlayFunctionContext<
TRenderer extends Renderer = Renderer,
TArgs = Args,
> extends StoryContext<TRenderer, TArgs> {}

export type StepLabel = string;

export type StepFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (
Expand All @@ -326,7 +304,7 @@ export type StepFunction<TRenderer extends Renderer = Renderer, TArgs = Args> =
) => Promise<void> | void;

export type PlayFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (
context: PlayFunctionContext<TRenderer, TArgs>
context: StoryContext<TRenderer, TArgs>
) => Promise<void> | void;

export type TestFunction<TRenderer extends Renderer = Renderer, TArgs = TRenderer['args']> = (
Expand Down
Loading
Loading