Skip to content

Commit

Permalink
Merge pull request #25449 from storybookjs/version-non-patch-from-8.0…
Browse files Browse the repository at this point in the history
….0-alpha.7

Release: Prerelease 8.0.0-alpha.8
  • Loading branch information
shilman authored Jan 6, 2024
2 parents 328712a + d70a3bf commit a0ea022
Show file tree
Hide file tree
Showing 125 changed files with 763 additions and 1,199 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 8.0.0-alpha.8

- Addon Links: Remove LinkTo from direct import - [#25418](https://github.com/storybookjs/storybook/pull/25418), thanks [@yannbf](https://github.com/yannbf)!
- Addon docs: Remove deprecated parameters - [#25469](https://github.com/storybookjs/storybook/pull/25469), thanks [@yannbf](https://github.com/yannbf)!
- Builder Vite: Remove StorybookViteConfig type in favor of StorybookConfig - [#25441](https://github.com/storybookjs/storybook/pull/25441), thanks [@yannbf](https://github.com/yannbf)!
- Core: Error on explicit actions while rendering or playing - [#25238](https://github.com/storybookjs/storybook/pull/25238), thanks [@kasperpeulen](https://github.com/kasperpeulen)!
- Core: Remove collapseAll and expandAll methods - [#25486](https://github.com/storybookjs/storybook/pull/25486), thanks [@yannbf](https://github.com/yannbf)!
- Core: Remove storyIndexers in favor of experimental_indexers - [#25468](https://github.com/storybookjs/storybook/pull/25468), thanks [@yannbf](https://github.com/yannbf)!
- Core: Remove unused staticDir type - [#25415](https://github.com/storybookjs/storybook/pull/25415), thanks [@yannbf](https://github.com/yannbf)!
- Doc blocks: Remove deprecated props from Description block - [#25457](https://github.com/storybookjs/storybook/pull/25457), thanks [@yannbf](https://github.com/yannbf)!
- Manager API: Remove deprecated navigateToSettingsPage method - [#25467](https://github.com/storybookjs/storybook/pull/25467), thanks [@yannbf](https://github.com/yannbf)!
- React: Remove deprecated setGlobalConfig portable stories api - [#25442](https://github.com/storybookjs/storybook/pull/25442), thanks [@yannbf](https://github.com/yannbf)!
- TypeScript: Remove deprecated addons module types - [#25485](https://github.com/storybookjs/storybook/pull/25485), thanks [@yannbf](https://github.com/yannbf)!
- Types: Remove DecoratorFn, Story, ComponentStory, ComponentStoryObj, ComponentStoryFn and ComponentMeta types - [#25477](https://github.com/storybookjs/storybook/pull/25477), thanks [@yannbf](https://github.com/yannbf)!
- Types: Remove Framework in favor of Renderer types - [#25476](https://github.com/storybookjs/storybook/pull/25476), thanks [@yannbf](https://github.com/yannbf)!
- UI: Remove deprecated WithTooltip props - [#25440](https://github.com/storybookjs/storybook/pull/25440), thanks [@yannbf](https://github.com/yannbf)!

## 8.0.0-alpha.7

- Addon-Docs: Upgrade to MDX3 - [#25303](https://github.com/storybookjs/storybook/pull/25303), thanks [@yannbf](https://github.com/yannbf)!
Expand Down
156 changes: 150 additions & 6 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
- [Require Svelte 4 and up](#require-svelte-4-and-up)
- [Deprecations which are now removed](#deprecations-which-are-now-removed)
- [--use-npm flag in storybook CLI](#--use-npm-flag-in-storybook-cli)
- [`setGlobalConfig` from `@storybook/react`](#setglobalconfig-from-storybookreact)
- [StorybookViteConfig type from @storybook/builder-vite](#storybookviteconfig-type-from-storybookbuilder-vite)
- [props from WithTooltipComponent from @storybook/components](#props-from-withtooltipcomponent-from-storybookcomponents)
- [LinkTo direct import from addon-links](#linkto-direct-import-from-addon-links)
- [DecoratorFn, Story, ComponentStory, ComponentStoryObj, ComponentStoryFn and ComponentMeta TypeScript types](#decoratorfn-story-componentstory-componentstoryobj-componentstoryfn-and-componentmeta-typescript-types)
- ["Framework" TypeScript types](#framework-typescript-types)
- [`navigateToSettingsPage` method from Storybook's manager-api](#navigatetosettingspage-method-from-storybooks-manager-api)
- [storyIndexers](#storyindexers)
- [Deprecated docs parameters](#deprecated-docs-parameters)
- [Description Doc block properties](#description-doc-block-properties)
- [Manager API expandAll and collapseAll methods](#manager-api-expandall-and-collapseall-methods)
- [From version 7.5.0 to 7.6.0](#from-version-750-to-760)
- [CommonJS with Vite is deprecated](#commonjs-with-vite-is-deprecated)
- [Using implicit actions during rendering is deprecated](#using-implicit-actions-during-rendering-is-deprecated)
Expand Down Expand Up @@ -573,6 +584,112 @@ Starting in 8.0, Storybook requires Svelte 4 and up.

The `--use-npm` is now removed. Use `--package-manager=npm` instead. [More info here](#cli-option---use-npm-deprecated).

#### `setGlobalConfig` from `@storybook/react`

The `setGlobalConfig` (used for reusing stories in your tests) is now removed in favor of `setProjectAnnotations`.

```ts
import { setProjectAnnotations } from `@storybook/testing-react`.
```

#### StorybookViteConfig type from @storybook/builder-vite

The `StorybookViteConfig` type is now removed in favor of `StorybookConfig`:

```ts
import type { StorybookConfig } from '@storybook/react-vite';
```

#### props from WithTooltipComponent from @storybook/components

The deprecated properties `tooltipShown`, `closeOnClick`, and `onVisibilityChange` of `WithTooltipComponent` from `@storybook/components` are now removed. Please replace them:

```tsx
<WithTooltip
closeOnClick // becomes closeOnOutsideClick
tooltipShown // becomes defaultVisible
onVisibilityChange // becomes onVisibleChange
>
...
</WithTooltip>
```

#### LinkTo direct import from addon-links

The `LinkTo` (React component) direct import from `@storybook/addon-links` is now removed. You have to import it from `@storybook/addon-links/react` instead.

```ts
// before
import LinkTo from '@storybook/addon-links';

// after
import LinkTo from '@storybook/addon-links/react';
```

#### DecoratorFn, Story, ComponentStory, ComponentStoryObj, ComponentStoryFn and ComponentMeta TypeScript types

The `Story` type is now removed in favor of `StoryFn` and `StoryObj`. More info [here](#story-type-deprecated).

The `DecoratorFn` type is now removed in favor of `Decorator`. [More info](#renamed-decoratorfn-to-decorator).

For React, the `ComponentStory`, `ComponentStoryObj`, `ComponentStoryFn` and `ComponentMeta` types are now removed in favor of `StoryFn`, `StoryObj` and `Meta`. [More info](#componentstory-componentstoryobj-componentstoryfn-and-componentmeta-types-are-deprecated).

#### "Framework" TypeScript types

The Framework types such as `ReactFramework` are now removed in favor of Renderer types such as `ReactRenderer`. This affects all frameworks. [More info](#renamed-xframework-to-xrenderer).

#### `navigateToSettingsPage` method from Storybook's manager-api

The `navigateToSettingsPage` method from manager-api is now removed in favor of `changeSettingsTab`.

```ts
export const Component = () => {
const api = useStorybookApi();

const someHandler = () => {
// Old method: api.navigateToSettingsPage('/settings/about');
api.changeSettingsTab('about'); // the /settings path is not necessary anymore
};

// ...
}
```

#### storyIndexers

The Storybook's main.js configuration property `storyIndexers` is now removed in favor of `experimental_indexers`. [More info](#storyindexers-is-replaced-with-experimental_indexers).

#### Deprecated docs parameters

The following story and meta parameters are now removed:

```ts
parameters.docs.iframeHeight // becomes docs.story.iframeHeight
parameters.docs.inlineStories // becomes docs.story.inline
parameters.jsx.transformSource // becomes parameters.docs.source.transform
parameters.docs.transformSource // becomes parameters.docs.source.transform
parameters.docs.source.transformSource // becomes parameters.docs.source.transform
```

More info [here](#autodocs-changes) and [here](#source-block).

#### Description Doc block properties

`children`, `markdown` and `type` are now removed in favor of the `of` property. [More info](#doc-blocks).

#### Manager API expandAll and collapseAll methods

The `collapseAll` and `expandAll` APIs (possibly used by addons) are now removed. Please emit events for these actions instead:

```ts
import { STORIES_COLLAPSE_ALL, STORIES_EXPAND_ALL } from '@storybook/core-events';
import { useStorybookApi } from '@storybook/manager-api';

const api = useStorybookApi()
api.collapseAll() // becomes api.emit(STORIES_COLLAPSE_ALL)
api.expandAll() // becomes api.emit(STORIES_EXPAND_ALL)
```

## From version 7.5.0 to 7.6.0

#### CommonJS with Vite is deprecated
Expand Down Expand Up @@ -2168,6 +2285,8 @@ During the 7.0 dev cycle we will be preparing recommendations and utilities to m

#### `Story` type deprecated

_Has codemod_

In 6.x you were able to do this:

```ts
Expand All @@ -2176,24 +2295,43 @@ import type { Story } from '@storybook/react';
export const MyStory: Story = () => <div />;
```

But this will produce a deprecation warning in 7.0 because `Story` has been deprecated.
To fix the deprecation warning, use the `StoryFn` type:
However with the introduction of CSF3, the `Story` type has been deprecated in favor of two other types: `StoryFn` for CSF2 and `StoryObj` for CSF3.

```ts
import type { StoryFn } from '@storybook/react';
import type { StoryFn, StoryObj } from '@storybook/react';

export const MyStory: StoryFn = () => <div />;
export const MyCsf2Story: StoryFn = () => <div />;
export const MyCsf3Story: StoryObj = {
render: () => <div />
};
```

This change is part of our move to CSF3, which uses objects instead of functions to represent stories.
You can read more about the CSF3 format here: https://storybook.js.org/blog/component-story-format-3-0/

We have set up a codemod that attempts to automatically migrate your code for you (update the glob to suit your needs):

```
npx storybook@next migrate upgrade-deprecated-types --glob="**/*.stories.tsx"
```

#### `ComponentStory`, `ComponentStoryObj`, `ComponentStoryFn` and `ComponentMeta` types are deprecated

The type of StoryObj and StoryFn have been changed in 7.0 so that both the "component" as "the props of the component" will be accepted as the generic parameter.
_Has codemod_

The type of `StoryObj` and `StoryFn` have been changed in 7.0 so that both the "component" as "the props of the component" will be accepted as the generic parameter. You can now replace the types:

```
ComponentStory -> StoryFn (CSF2) or StoryObj (CSF3)
ComponentStoryObj -> StoryObj
ComponentStoryFn -> StoryFn
ComponentMeta -> Meta
```

Here are a few examples:

```ts
import type { Story } from '@storybook/react';
import type { StoryFn, StoryObj } from '@storybook/react';
import { Button, ButtonProps } from './Button';
// This works in 7.0, making the ComponentX types redundant.
Expand All @@ -2213,6 +2351,12 @@ export const CSF2Story: StoryFn<ButtonProps> = (args) => <Button {...args} />;
CSF2Story.args = { label: 'Label' };
```

We have set up a codemod that attempts to automatically migrate your code for you (update the glob to suit your needs):

```
npx storybook@next migrate upgrade-deprecated-types --glob="**/*.stories.tsx"
```

#### Renamed `renderToDOM` to `renderToCanvas`

The "rendering" function that renderers (ex-frameworks) must export (`renderToDOM`) has been renamed to `renderToCanvas` to acknowledge that some consumers of frameworks/the preview do not work with DOM elements.
Expand Down
2 changes: 1 addition & 1 deletion code/addons/docs/docs/docspage.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ addParameters({
});
```

With that function, anyone using the docs addon for `@storybook/vue` can make their stories render inline, either globally with the `inlineStories` docs parameter, or on a per-story-basis using the `inline` prop on the `<Story>` doc block. If you come up with an elegant and flexible implementation for the `prepareForInline` function for your own framework, let us know! We'd love to make it the default configuration, to make inline stories more accessible for a larger variety of frameworks!
With that function, anyone using the docs addon for `@storybook/vue` can make their stories render inline, either globally with the `docs.story.inline` parameter, or on a per-story-basis using the `inline` prop on the `<Story>` doc block. If you come up with an elegant and flexible implementation for the `prepareForInline` function for your own framework, let us know! We'd love to make it the default configuration, to make inline stories more accessible for a larger variety of frameworks!

## Show/Hide code

Expand Down
1 change: 1 addition & 0 deletions code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"devDependencies": {
"@mdx-js/mdx": "^3.0.0",
"@rollup/pluginutils": "^5.0.2",
"@storybook/test": "workspace:*",
"typescript": "^5.3.2",
"vite": "^4.0.4"
},
Expand Down
3 changes: 2 additions & 1 deletion code/addons/docs/template/stories/docspage/basic.stories.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { global as globalThis } from '@storybook/global';
import { fn } from '@storybook/test';

export default {
component: globalThis.Components.Button,
tags: ['autodocs'],
args: { label: 'Click Me!' },
args: { label: 'Click Me!', onClick: fn() },
parameters: { chromatic: { disable: true } },
};

Expand Down
20 changes: 13 additions & 7 deletions code/addons/interactions/src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import React, { Fragment, memo, useEffect, useMemo, useRef, useState } from 'rea
import { useAddonState, useChannel, useParameter } from '@storybook/manager-api';
import {
FORCE_REMOUNT,
IGNORED_EXCEPTION,
STORY_RENDER_PHASE_CHANGED,
STORY_THREW_EXCEPTION,
PLAY_FUNCTION_THREW_EXCEPTION,
UNHANDLED_ERRORS_WHILE_PLAYING,
} from '@storybook/core-events';
import { EVENTS, type Call, CallStates, type LogItem } from '@storybook/instrumenter';

Expand Down Expand Up @@ -91,6 +91,7 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
hasException: false,
caughtException: undefined,
interactionsCount: 0,
unhandledErrors: undefined,
});

// local state
Expand All @@ -104,6 +105,7 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
interactions = [],
isPlaying = false,
caughtException = undefined,
unhandledErrors = undefined,
} = addonState;

// Log and calls are tracked in a ref so we don't needlessly rerender.
Expand Down Expand Up @@ -157,6 +159,7 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
hasException: false,
caughtException: undefined,
interactionsCount: 0,
unhandledErrors: undefined,
});
return;
}
Expand All @@ -180,11 +183,10 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
set((s) => ({ ...s, isErrored: true }));
},
[PLAY_FUNCTION_THREW_EXCEPTION]: (e) => {
if (e?.message !== IGNORED_EXCEPTION.message) {
set((s) => ({ ...s, caughtException: e }));
} else {
set((s) => ({ ...s, caughtException: undefined }));
}
set((s) => ({ ...s, caughtException: e }));
},
[UNHANDLED_ERRORS_WHILE_PLAYING]: (e) => {
set((s) => ({ ...s, unhandledErrors: e }));
},
},
[collapsed]
Expand Down Expand Up @@ -224,7 +226,10 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
const [fileName] = storyFilePath.toString().split('/').slice(-1);
const scrollToTarget = () => scrollTarget?.scrollIntoView({ behavior: 'smooth', block: 'end' });

const hasException = !!caughtException || interactions.some((v) => v.status === CallStates.ERROR);
const hasException =
!!caughtException ||
!!unhandledErrors ||
interactions.some((v) => v.status === CallStates.ERROR);

if (isErrored) {
return <Fragment key="interactions" />;
Expand All @@ -240,6 +245,7 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
fileName={fileName}
hasException={hasException}
caughtException={caughtException}
unhandledErrors={unhandledErrors}
isPlaying={isPlaying}
pausedAt={pausedAt}
endRef={endRef}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentStoryObj, ComponentMeta } from '@storybook/react';
import type { StoryObj, Meta } from '@storybook/react';
import { expect } from '@storybook/jest';
import { CallStates } from '@storybook/instrumenter';
import { userEvent, within } from '@storybook/testing-library';
Expand All @@ -7,7 +7,7 @@ import { getCalls } from '../mocks';
import { Interaction } from './Interaction';
import SubnavStories from './Subnav.stories';

type Story = ComponentStoryObj<typeof Interaction>;
type Story = StoryObj<typeof Interaction>;

export default {
title: 'Addons/Interactions/Interaction',
Expand All @@ -17,7 +17,7 @@ export default {
controls: SubnavStories.args.controls,
controlStates: SubnavStories.args.controlStates,
},
} as ComponentMeta<typeof Interaction>;
} as Meta<typeof Interaction>;

export const Active: Story = {
args: {
Expand Down
6 changes: 3 additions & 3 deletions code/addons/interactions/src/components/Interaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MethodCall } from './MethodCall';
import { StatusIcon } from './StatusIcon';

import type { Controls } from './InteractionsPanel';
import { isJestError } from '../utils';

const MethodCallWrapper = styled.div(() => ({
fontFamily: typography.fonts.mono,
Expand Down Expand Up @@ -112,16 +113,15 @@ const RowMessage = styled('div')(({ theme }) => ({
},
}));

const Exception = ({ exception }: { exception: Call['exception'] }) => {
if (exception.message.startsWith('expect(')) {
export const Exception = ({ exception }: { exception: Call['exception'] }) => {
if (isJestError(exception)) {
return <MatcherResult {...exception} />;
}
const paragraphs = exception.message.split('\n\n');
const more = paragraphs.length > 1;
return (
<RowMessage>
<pre>{paragraphs[0]}</pre>

{exception.showDiff && exception.diff ? (
<>
<br />
Expand Down
Loading

0 comments on commit a0ea022

Please sign in to comment.