Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: Prerelease 8.0.0-beta.3 #26004

Merged
merged 83 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
777f1bf
Update example to import a raw markdown file
rwaight Feb 1, 2024
1ae9e0b
Bump user-event to 14.5.2
kasperpeulen Feb 2, 2024
923deb7
refactor cli to add autoblockers
ndelangen Feb 6, 2024
aeac067
add tests & fix some review comments
ndelangen Feb 7, 2024
1c3aa9b
fix migrate command that calls the changed runFixes fn
ndelangen Feb 7, 2024
da51fee
cleanup
ndelangen Feb 7, 2024
8af5a52
cleanup
ndelangen Feb 7, 2024
d4ca826
remove the types from jsdoc
ndelangen Feb 7, 2024
ab58f40
the best i can make it.. #bikeshedding
ndelangen Feb 7, 2024
668c3a8
expand scope of autoblock for react-script to also block vue2
ndelangen Feb 8, 2024
2bfea5f
add a step in between commander & calling the automigrate function so…
ndelangen Feb 8, 2024
332b8da
fix incorrect logic on detecting stories.mdx
ndelangen Feb 8, 2024
c20c3d8
make it say 8.0.0
ndelangen Feb 8, 2024
9ca5d50
check for the INSTALLED version, not the latest
ndelangen Feb 8, 2024
b12052c
add a automigration for a old vite version and another one for ensur…
ndelangen Feb 8, 2024
30bed62
add migration note, and early return
ndelangen Feb 8, 2024
274049b
Merge branch 'next' into norbert/upgrade-auto-blockers
ndelangen Feb 8, 2024
cf4bdb5
Merge branch 'next' into norbert/upgrade-auto-blockers
ndelangen Feb 8, 2024
4cd82bb
Add migrate-to-test-package codemod
kasperpeulen Feb 8, 2024
816a8df
Prompt the codemod in an automigration
kasperpeulen Feb 8, 2024
37c5f10
Merge remote-tracking branch 'origin/next' into kasper/test-codemod
kasperpeulen Feb 9, 2024
be2f70e
Add the new entry
kasperpeulen Feb 9, 2024
1350918
Apply prettier
kasperpeulen Feb 9, 2024
e2bf38b
Change wording
kasperpeulen Feb 9, 2024
6d6789f
Change wording
kasperpeulen Feb 9, 2024
2e3cdc6
Update snapshot
kasperpeulen Feb 9, 2024
3b20982
use getFrameworkPackageName
ndelangen Feb 9, 2024
570b3ba
Use default prettier setting if we can not find a config
kasperpeulen Feb 9, 2024
a57d58b
Merge branch 'next' into norbert/upgrade-auto-blockers
ndelangen Feb 9, 2024
b0ece9f
Fix the test
kasperpeulen Feb 9, 2024
b8e1a75
performed some manual testing and found some issues
ndelangen Feb 9, 2024
5f33810
Update CHANGELOG.md for v7.6.14 [skip ci]
storybook-bot Feb 10, 2024
fb144f2
fix review comment
ndelangen Feb 12, 2024
bd369e5
Merge branch 'next' into norbert/upgrade-auto-blockers
ndelangen Feb 12, 2024
13dd363
Fix test name
kasperpeulen Feb 12, 2024
834d73b
Fix lint
kasperpeulen Feb 12, 2024
2ab74c7
Fix lint
kasperpeulen Feb 12, 2024
80267b2
only provide a play function wrapper if it exists
yannbf Feb 12, 2024
deeedc8
sb -> storybook
kasperpeulen Feb 12, 2024
f31380c
Fix unit test
kasperpeulen Feb 12, 2024
68e6cb0
add more autoblockers for dependencies & add a --force flag to skip a…
ndelangen Feb 12, 2024
369704b
move nodeversion check to autoblock
ndelangen Feb 12, 2024
0003c40
remove from list
ndelangen Feb 12, 2024
e6fea3f
Fix CI
kasperpeulen Feb 12, 2024
6344a4a
Apply suggestions from code review
ndelangen Feb 12, 2024
a4d4087
apply https://github.com/storybookjs/storybook/pull/25934#discussion_…
ndelangen Feb 12, 2024
b3e2aa7
Merge branch 'next' into kasper/test-codemod
kasperpeulen Feb 12, 2024
c73de4b
Merge pull request #25958 from storybookjs/kasper/test-codemod
kasperpeulen Feb 12, 2024
3ae39b6
Merge pull request #25974 from storybookjs/yann/improve-play-fn-porta…
yannbf Feb 12, 2024
671c325
Update import markdown example
rwaight Feb 12, 2024
243a60d
add back the removed renderer mapping
ndelangen Feb 13, 2024
d79043f
Update code/lib/cli/src/autoblock/block-stories-mdx.ts
ndelangen Feb 13, 2024
2aec740
fixes
ndelangen Feb 13, 2024
6164216
Merge branch 'norbert/upgrade-auto-blockers' of https://github.com/st…
ndelangen Feb 13, 2024
016ac00
Merge branch 'next' into norbert/upgrade-auto-blockers
ndelangen Feb 13, 2024
ece84b9
Merge pull request #25934 from storybookjs/norbert/upgrade-auto-blockers
valentinpalkovic Feb 13, 2024
f94366e
Update CHANGELOG.md for v7.6.15 [skip ci]
storybook-bot Feb 13, 2024
87bf8f0
use aliases instead of dedupe to deduplicate storybook dependencies i…
JReinhold Feb 13, 2024
c64041e
add missing dirname to require.resolve calls
JReinhold Feb 13, 2024
152d96d
Do add spy to action for explicit actions
kasperpeulen Feb 14, 2024
50edeef
Merge pull request #26024 from storybookjs/jeppe/25964
JReinhold Feb 14, 2024
6cdf916
Merge branch 'next' into patch-1
jonniebigodes Feb 14, 2024
336fe8a
Merge pull request #25862 from rwaight/patch-1
jonniebigodes Feb 14, 2024
dbe2b59
Addon Themes: make type generic less strict
yannbf Feb 15, 2024
999fc2a
Merge pull request #26042 from storybookjs/yann/fix-addon-themes-types
yannbf Feb 15, 2024
dc879b4
Do add spy to action for explicit actions
kasperpeulen Feb 15, 2024
0ec21a2
Only traverse plain objects
kasperpeulen Feb 15, 2024
4664dc1
Update CHANGELOG.md for v7.6.16 [skip ci]
storybook-bot Feb 15, 2024
e50fb33
Fix key passing
kasperpeulen Feb 15, 2024
fe0448b
Remove log
kasperpeulen Feb 15, 2024
45abcf3
Merge branch 'next' into kasper/bump-user-event
kasperpeulen Feb 15, 2024
2c0ba07
Add migration note about `addons.setConfig`
kylegach Feb 15, 2024
f24784d
fix the logic adding the caret to upgrade
ndelangen Feb 15, 2024
2a82b79
Revert "fix the logic adding the caret to upgrade"
ndelangen Feb 15, 2024
e6b89d7
Merge pull request #26039 from storybookjs/update-migration-notes-add…
kylegach Feb 15, 2024
2e9b355
Fix depth issue
kasperpeulen Feb 15, 2024
1576b2a
Add step back
kasperpeulen Feb 15, 2024
95c7048
Remove
kasperpeulen Feb 15, 2024
be84a02
Merge pull request #26033 from storybookjs/kasper/spy-on-explicit-act…
kasperpeulen Feb 15, 2024
0e66ecf
Merge branch 'next' into kasper/bump-user-event
kasperpeulen Feb 15, 2024
d236f77
Merge pull request #25889 from storybookjs/kasper/bump-user-event
kasperpeulen Feb 16, 2024
da249fa
Write changelog for 8.0.0-beta.3 [skip ci]
storybook-bot Feb 16, 2024
9b53955
Update CHANGELOG.prerelease.md
shilman Feb 17, 2024
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 7.6.16

- Addon Themes: Make type generic less strict - [#26042](https://github.com/storybookjs/storybook/pull/26042), thanks [@yannbf](https://github.com/yannbf)!
- Interaction: Make sure that adding spies doesn't cause infinite loops with self referencing args [#26019](https://github.com/storybookjs/storybook/pull/26019), thanks @kasperpeulen!

## 7.6.15

This release accidentally didn't contain anything.

## 7.6.14

- Core: Fix boolean `true` args in URL getting ignored - [#25950](https://github.com/storybookjs/storybook/pull/25950), thanks [@JReinhold](https://github.com/JReinhold)!

## 7.6.13

- Next.js: Fix frameworkOptions resolution - [#25907](https://github.com/storybookjs/storybook/pull/25907), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 8.0.0-beta.3

- Addon-actions: Add spy to action for explicit actions - [#26033](https://github.com/storybookjs/storybook/pull/26033), thanks [@kasperpeulen](https://github.com/kasperpeulen)!
- Addon-themes: Make type generic less strict - [#26042](https://github.com/storybookjs/storybook/pull/26042), thanks [@yannbf](https://github.com/yannbf)!
- Addon-docs: Fix pnpm+Vite failing to build with `@storybook/theming` Rollup error - [#26024](https://github.com/storybookjs/storybook/pull/26024), thanks [@JReinhold](https://github.com/JReinhold)!
- CLI: Refactor to add autoblockers - [#25934](https://github.com/storybookjs/storybook/pull/25934), thanks [@ndelangen](https://github.com/ndelangen)!
- Codemod: Migrate to test package - [#25958](https://github.com/storybookjs/storybook/pull/25958), thanks [@kasperpeulen](https://github.com/kasperpeulen)!
- Portable stories: Only provide a play function wrapper if it exists - [#25974](https://github.com/storybookjs/storybook/pull/25974), thanks [@yannbf](https://github.com/yannbf)!
- Test: Bump user-event to 14.5.2 - [#25889](https://github.com/storybookjs/storybook/pull/25889), thanks [@kasperpeulen](https://github.com/kasperpeulen)!

## 8.0.0-beta.2

- Core: Fix boolean `true` args in URL getting ignored - [#25950](https://github.com/storybookjs/storybook/pull/25950), thanks [@JReinhold](https://github.com/JReinhold)!
Expand Down
101 changes: 99 additions & 2 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<h1>Migration</h1>

- [From version 7.x to 8.0.0](#from-version-7x-to-800)
- [Type change in `composeStories` API](#type-change-in-composestories-api)
- [Tab addons are now routed to a query parameter](#tab-addons-are-now-routed-to-a-query-parameter)
- [Default keyboard shortcuts changed](#default-keyboard-shortcuts-changed)
- [Manager addons are now rendered with React 18](#manager-addons-are-now-rendered-with-react-18)
- [Removal of `storiesOf`-API](#removal-of-storiesof-api)
- [Removed deprecated shim packages](#removed-deprecated-shim-packages)
- [Framework-specific Vite plugins have to be explicitly added](#framework-specific-vite-plugins-have-to-be-explicitly-added)
- [For React:](#for-react)
- [For Vue:](#for-vue)
- [For Svelte (without Sveltekit):](#for-svelte-without-sveltekit)
- [For Preact:](#for-preact)
- [For Solid:](#for-solid)
- [For Qwik:](#for-qwik)
- [TurboSnap Vite plugin is no longer needed](#turbosnap-vite-plugin-is-no-longer-needed)
- [Implicit actions can not be used during rendering (for example in the play function)](#implicit-actions-can-not-be-used-during-rendering-for-example-in-the-play-function)
- [MDX related changes](#mdx-related-changes)
Expand Down Expand Up @@ -120,6 +127,7 @@
- [Story context is prepared before for supporting fine grained updates](#story-context-is-prepared-before-for-supporting-fine-grained-updates)
- [Changed decorator order between preview.js and addons/frameworks](#changed-decorator-order-between-previewjs-and-addonsframeworks)
- [Dark mode detection](#dark-mode-detection)
- [`addons.setConfig` should now be imported from `@storybook/manager-api`.](#addonssetconfig-should-now-be-imported-from-storybookmanager-api)
- [7.0 core addons changes](#70-core-addons-changes)
- [Removed auto injection of @storybook/addon-actions decorator](#removed-auto-injection-of-storybookaddon-actions-decorator)
- [Addon-backgrounds: Removed deprecated grid parameter](#addon-backgrounds-removed-deprecated-grid-parameter)
Expand Down Expand Up @@ -392,6 +400,23 @@

## From version 7.x to 8.0.0

### Type change in `composeStories` API

There is a TypeScript type change in the `play` function returned from `composeStories` or `composeStory` in `@storybook/react` or `@storybook/vue3`, where before it was always defined, now it is potentially undefined. This means that you might have to make a small change in your code, such as:

```ts
const { Primary } = composeStories(stories)

// before
await Primary.play(...)

// after
await Primary.play?.(...) // if you don't care whether the play function exists
await Primary.play!(...) // if you want a runtime error when the play function does not exist
```

There are plans to make the type of the play function be inferred based on your imported story's play function in a near future, so the types will be 100% accurate.

### Tab addons are now routed to a query parameter

The URL of a tab used to be: `http://localhost:6006/?path=/my-addon-tab/my-story`.
Expand Down Expand Up @@ -444,23 +469,82 @@ In Storybook 7, these packages existed for backwards compatibility, but were mar
- `@storybook/store` - this package has been merged into `@storybook/preview-api`.
- `@storybook/api` - this package has been replaced with `@storybook/manager-api`.

This section explains the rationale, and the required changed you might have to make: [New Addons API](#new-addons-api)
These sections explain the rationale, and the required changes you might have to make:

- [New Addons API](#new-addons-api)
- [`addons.setConfig` should now be imported from `@storybook/manager-api`.](#addonssetconfig-should-now-be-imported-from-storybookmanager-api)

### Framework-specific Vite plugins have to be explicitly added

In Storybook 7, we would automatically add frameworks-specific Vite plugins, e.g. `@vitejs/plugin-react` if not installed.
In Storybook 8 those plugins have to be added explicitly in the user's `vite.config.ts`:

#### For React:

```ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
});
```

#### For Vue:

```ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
plugins: [vue()],
});
```

#### For Svelte (without Sveltekit):

```ts
import { defineConfig } from "vite";
import svelte from "@sveltejs/vite-plugin-svelte";

export default defineConfig({
plugins: [svelte()],
});
```

#### For Preact:

```ts
import { defineConfig } from "vite";
import preact from "@preact/preset-vite";

export default defineConfig({
plugins: [preact()],
});
```

#### For Solid:

```ts
import { defineConfig } from "vite";
import solid from "vite-plugin-solid";

export default defineConfig({
plugins: [solid()],
});
```

#### For Qwik:

```ts
import { defineConfig } from "vite";
import qwik from "vite-plugin-qwik";

export default defineConfig({
plugins: [qwik()],
});
```

### TurboSnap Vite plugin is no longer needed

At least in build mode, `builder-vite` now supports the `--webpack-stats-json` flag and will output `preview-stats.json`.
Expand Down Expand Up @@ -1949,6 +2033,19 @@ Earlier versions used the light theme by default, so if you don't set a theme an

To learn more about theming, read our [documentation](https://storybook.js.org/docs/react/configure/theming).

#### `addons.setConfig` should now be imported from `@storybook/manager-api`.

The previous package, `@storybook/addons`, is now deprecated and will be removed in 8.0.

```diff
- import { addons } from '@storybook/addons';
+ import { addons } from '@storybook/manager-api';

addons.setConfig({
// ...
})
```

### 7.0 core addons changes

#### Removed auto injection of @storybook/addon-actions decorator
Expand Down
1 change: 1 addition & 0 deletions code/addons/actions/src/runtime/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function action(name: string, options: ActionOptions = {}): HandlerFuncti
channel.emit(EVENT_ID, actionDisplayToEmit);
};
handler.isAction = true;
handler.implicit = options.implicit;

return handler;
}
8 changes: 7 additions & 1 deletion code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ export const viteFinal = async (config: any, options: Options) => {
react,
'react-dom': reactDom,
'@mdx-js/react': mdx,
/**
* The following aliases are used to ensure a single instance of these packages are used in situations where they are duplicated
* The packages will be duplicated by the package manager when the user has react installed with another version than 18.2.0
*/
'@storybook/theming': dirname(require.resolve('@storybook/theming')),
'@storybook/components': dirname(require.resolve('@storybook/components')),
'@storybook/blocks': dirname(require.resolve('@storybook/blocks')),
},
dedupe: ['@storybook/theming', '@storybook/components', '@storybook/blocks'],
},
}),
};
Expand Down
63 changes: 42 additions & 21 deletions code/addons/interactions/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-underscore-dangle */
import type {
Args,
LoaderFunction,
ArgsEnhancer,
PlayFunction,
PlayFunctionContext,
Renderer,
StepLabel,
} from '@storybook/types';
import { fn, isMockFunction } from '@storybook/test';
import { instrument } from '@storybook/instrumenter';

export const { step: runStep } = instrument(
Expand All @@ -16,26 +16,47 @@ export const { step: runStep } = instrument(
{ intercept: true }
);

const instrumentSpies: LoaderFunction = ({ initialArgs }) => {
const argTypesWithAction = Object.entries(initialArgs).filter(
([, value]) =>
typeof value === 'function' &&
'_isMockFunction' in value &&
value._isMockFunction &&
!value._instrumented
);

return argTypesWithAction.reduce((acc, [key, value]) => {
const instrumented = instrument({ [key]: () => value }, { retain: true })[key];
acc[key] = instrumented();
// this enhancer is being called multiple times

value._instrumented = true;
return acc;
}, {} as Args);
const traverseArgs = (value: unknown, depth = 0, key?: string): any => {
// Make sure to not get in infinite loops with self referencing args
if (depth > 5) return value;
if (value == null) return value;
if (isMockFunction(value)) {
// Makes sure we get the arg name in the interactions panel
if (key) value.mockName(key);
return value;
}

// wrap explicit actions in a spy
if (
typeof value === 'function' &&
'isAction' in value &&
value.isAction &&
!('implicit' in value && value.implicit)
) {
const mock = fn(value as any);
if (key) mock.mockName(key);
return mock;
}

if (Array.isArray(value)) {
depth++;
return value.map((item) => traverseArgs(item, depth));
}

if (typeof value === 'object' && value.constructor === Object) {
depth++;
// We have to mutate the original object for this to survive HMR.
for (const [k, v] of Object.entries(value)) {
(value as Record<string, unknown>)[k] = traverseArgs(v, depth, k);
}
return value;
}
return value;
};

export const argsEnhancers = [instrumentSpies];
const wrapActionsInSpyFns: ArgsEnhancer<Renderer> = ({ initialArgs }) => traverseArgs(initialArgs);

export const argsEnhancers = [wrapActionsInSpyFns];

export const parameters = {
throwPlayFunctionExceptions: false,
Expand Down
3 changes: 2 additions & 1 deletion code/addons/themes/src/decorators/class-name.decorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const DEFAULT_ELEMENT_SELECTOR = 'html';

const classStringToArray = (classString: string) => classString.split(' ').filter(Boolean);

export const withThemeByClassName = <TRenderer extends Renderer = Renderer>({
// TODO check with @kasperpeulen: change the types so they can be correctly inferred from context e.g. <Story extends (...args: any[]) => any>
export const withThemeByClassName = <TRenderer extends Renderer = any>({
themes,
defaultTheme,
parentSelector = DEFAULT_ELEMENT_SELECTOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export interface DataAttributeStrategyConfiguration {
const DEFAULT_ELEMENT_SELECTOR = 'html';
const DEFAULT_DATA_ATTRIBUTE = 'data-theme';

export const withThemeByDataAttribute = <TRenderer extends Renderer = Renderer>({
// TODO check with @kasperpeulen: change the types so they can be correctly inferred from context e.g. <Story extends (...args: any[]) => any>
export const withThemeByDataAttribute = <TRenderer extends Renderer = any>({
themes,
defaultTheme,
parentSelector = DEFAULT_ELEMENT_SELECTOR,
Expand Down
3 changes: 2 additions & 1 deletion code/addons/themes/src/decorators/provider.decorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export interface ProviderStrategyConfiguration {

const pluckThemeFromKeyPairTuple = ([_, themeConfig]: [string, Theme]): Theme => themeConfig;

export const withThemeFromJSXProvider = <TRenderer extends Renderer = Renderer>({
// TODO check with @kasperpeulen: change the types so they can be correctly inferred from context e.g. <Story extends (...args: any[]) => any>
export const withThemeFromJSXProvider = <TRenderer extends Renderer = any>({
Provider,
GlobalStyles,
defaultTheme,
Expand Down
Loading
Loading