Skip to content

Commit

Permalink
Merge pull request #30124 from storybookjs/version-non-patch-from-8.5…
Browse files Browse the repository at this point in the history
….0-beta.4

Release: Prerelease 8.5.0-beta.5
  • Loading branch information
yannbf authored Dec 23, 2024
2 parents cf55526 + e5c6c79 commit 0abf3ce
Show file tree
Hide file tree
Showing 30 changed files with 370 additions and 169 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 8.5.0-beta.5

- Addon Test: Only reset story count on file change when watch mode is enabled - [#30121](https://github.com/storybookjs/storybook/pull/30121), thanks @ghengeveld!
- Build: Revert Downgrade to esbuild 0.24.0 - [#30120](https://github.com/storybookjs/storybook/pull/30120), thanks @yannbf!
- Core: Fix `ERR_PACKAGE_PATH_NOT_EXPORTED` in `@storybook/node-logger` - [#30093](https://github.com/storybookjs/storybook/pull/30093), thanks @JReinhold!
- React: Use Act wrapper in Storybook for component rendering - [#30037](https://github.com/storybookjs/storybook/pull/30037), thanks @valentinpalkovic!
- Vite: Add extra entries to `optimizeDeps` - [#30117](https://github.com/storybookjs/storybook/pull/30117), thanks @ndelangen!

## 8.5.0-beta.4

- Addon Themes: Deprecate useThemeParameters - [#30111](https://github.com/storybookjs/storybook/pull/30111), thanks @yannbf!
Expand Down
40 changes: 28 additions & 12 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<h1>Migration</h1>

- [From version 8.4.x to 8.5.x](#from-version-84x-to-85x)
- [Introducing features.developmentModeForBuild](#introducing-featuresdevelopmentmodeforbuild)
- [Added source code panel to docs](#added-source-code-panel-to-docs)
- [Addon-a11y: Component test integration](#addon-a11y-component-test-integration)
- [Addon-a11y: Deprecated `parameters.a11y.manual`](#addon-a11y-deprecated-parametersa11ymanual)
Expand Down Expand Up @@ -110,17 +111,17 @@
- [Tab addons cannot manually route, Tool addons can filter their visibility via tabId](#tab-addons-cannot-manually-route-tool-addons-can-filter-their-visibility-via-tabid)
- [Removed `config` preset](#removed-config-preset-1)
- [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)
- [typescript.skipBabel deprecated](#typescriptskipbabel-deprecated)
- [Primary doc block accepts of prop](#primary-doc-block-accepts-of-prop)
- [Addons no longer need a peer dependency on React](#addons-no-longer-need-a-peer-dependency-on-react)
- [CommonJS with Vite is deprecated](#commonjs-with-vite-is-deprecated)
- [Using implicit actions during rendering is deprecated](#using-implicit-actions-during-rendering-is-deprecated)
- [typescript.skipBabel deprecated](#typescriptskipbabel-deprecated)
- [Primary doc block accepts of prop](#primary-doc-block-accepts-of-prop)
- [Addons no longer need a peer dependency on React](#addons-no-longer-need-a-peer-dependency-on-react)
- [From version 7.4.0 to 7.5.0](#from-version-740-to-750)
- [`storyStoreV6` and `storiesOf` is deprecated](#storystorev6-and-storiesof-is-deprecated)
- [`storyIndexers` is replaced with `experimental_indexers`](#storyindexers-is-replaced-with-experimental_indexers)
- [`storyStoreV6` and `storiesOf` is deprecated](#storystorev6-and-storiesof-is-deprecated)
- [`storyIndexers` is replaced with `experimental_indexers`](#storyindexers-is-replaced-with-experimental_indexers)
- [From version 7.0.0 to 7.2.0](#from-version-700-to-720)
- [Addon API is more type-strict](#addon-api-is-more-type-strict)
- [Addon-controls hideNoControlsWarning parameter is deprecated](#addon-controls-hidenocontrolswarning-parameter-is-deprecated)
- [Addon API is more type-strict](#addon-api-is-more-type-strict)
- [Addon-controls hideNoControlsWarning parameter is deprecated](#addon-controls-hidenocontrolswarning-parameter-is-deprecated)
- [From version 6.5.x to 7.0.0](#from-version-65x-to-700)
- [7.0 breaking changes](#70-breaking-changes)
- [Dropped support for Node 15 and below](#dropped-support-for-node-15-and-below)
Expand All @@ -146,7 +147,7 @@
- [Deploying build artifacts](#deploying-build-artifacts)
- [Dropped support for file URLs](#dropped-support-for-file-urls)
- [Serving with nginx](#serving-with-nginx)
- [Ignore story files from node\_modules](#ignore-story-files-from-node_modules)
- [Ignore story files from node_modules](#ignore-story-files-from-node_modules)
- [7.0 Core changes](#70-core-changes)
- [7.0 feature flags removed](#70-feature-flags-removed)
- [Story context is prepared before for supporting fine grained updates](#story-context-is-prepared-before-for-supporting-fine-grained-updates)
Expand All @@ -160,7 +161,7 @@
- [Addon-interactions: Interactions debugger is now default](#addon-interactions-interactions-debugger-is-now-default)
- [7.0 Vite changes](#70-vite-changes)
- [Vite builder uses Vite config automatically](#vite-builder-uses-vite-config-automatically)
- [Vite cache moved to node\_modules/.cache/.vite-storybook](#vite-cache-moved-to-node_modulescachevite-storybook)
- [Vite cache moved to node_modules/.cache/.vite-storybook](#vite-cache-moved-to-node_modulescachevite-storybook)
- [7.0 Webpack changes](#70-webpack-changes)
- [Webpack4 support discontinued](#webpack4-support-discontinued)
- [Babel mode v7 exclusively](#babel-mode-v7-exclusively)
Expand Down Expand Up @@ -211,7 +212,7 @@
- [Dropped addon-docs manual babel configuration](#dropped-addon-docs-manual-babel-configuration)
- [Dropped addon-docs manual configuration](#dropped-addon-docs-manual-configuration)
- [Autoplay in docs](#autoplay-in-docs)
- [Removed STORYBOOK\_REACT\_CLASSES global](#removed-storybook_react_classes-global)
- [Removed STORYBOOK_REACT_CLASSES global](#removed-storybook_react_classes-global)
- [7.0 Deprecations and default changes](#70-deprecations-and-default-changes)
- [storyStoreV7 enabled by default](#storystorev7-enabled-by-default)
- [`Story` type deprecated](#story-type-deprecated)
Expand Down Expand Up @@ -426,6 +427,21 @@

## From version 8.4.x to 8.5.x

### Introducing features.developmentModeForBuild

As part of our ongoing efforts to improve the testability and debuggability of Storybook, we are introducing a new feature flag: `developmentModeForBuild`. This feature flag allows you to set `process.env.NODE_ENV` to `development` in built Storybooks, enabling development-related optimizations that are typically disabled in production builds.

In development mode, React and other libraries often include additional checks and warnings that help catch potential issues early. These checks are usually stripped out in production builds to optimize performance. However, when running tests or debugging issues in a built Storybook, having these additional checks can be incredibly valuable. One such feature is React's `act`, which ensures that all updates related to a test are processed and applied before making assertions. `act` is crucial for reliable and predictable test results, but it only works correctly when `NODE_ENV` is set to `development`.

```js
// main.js
export default {
features: {
developmentModeForBuild: true,
},
};
```

### Added source code panel to docs

Starting in 8.5, Storybook Docs (`@storybook/addon-docs`) automatically adds a new addon panel to stories that displays a source snippet beneath each story. This works similarly to the existing [source snippet doc block](https://storybook.js.org/docs/writing-docs/doc-blocks#source), but in the story view. It is intended to replace the [Storysource addon](https://storybook.js.org/addons/@storybook/addon-storysource).
Expand Down
1 change: 1 addition & 0 deletions code/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const config: StorybookConfig = {
features: {
viewportStoryGlobals: true,
backgroundsStoryGlobals: true,
developmentModeForBuild: true,
},
viteFinal: async (viteConfig, { configType }) => {
const { mergeConfig } = await import('vite');
Expand Down
3 changes: 2 additions & 1 deletion code/addons/test/src/node/vitest-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,14 @@ export class VitestManager {
const id = slash(file);
this.vitest?.logger.clearHighlightCache(id);
this.updateLastChanged(id);
this.storyCountForCurrentRun = 0;

// when watch mode is disabled, don't trigger any tests (below)
// but still invalidate the cache for the changed file, which is handled above
if (!this.testManager.config.watchMode) {
return;
}

this.storyCountForCurrentRun = 0;
await this.runAffectedTests(file);
}

Expand Down
17 changes: 15 additions & 2 deletions code/builders/builder-vite/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,22 @@ export async function build(options: Options) {
}
: {}),
},
}).build;
} as InlineConfig).build;

const finalConfig = await presets.apply('viteFinal', config, options);
const finalConfig = (await presets.apply('viteFinal', config, options)) as InlineConfig;

if (options.features?.developmentModeForBuild) {
finalConfig.plugins?.push({
name: 'storybook:define-env',
config: () => {
return {
define: {
'process.env.NODE_ENV': JSON.stringify('development'),
},
};
},
});
}

const turbosnapPluginName = 'rollup-plugin-turbosnap';
const hasTurbosnapPlugin =
Expand Down
2 changes: 0 additions & 2 deletions code/builders/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { readFile } from 'node:fs/promises';
import { NoStatsForViteDevError } from 'storybook/internal/server-errors';
import type { Middleware, Options } from 'storybook/internal/types';

import sirv from 'sirv';
import { corePath } from 'storybook/core-path';
import type { ViteDevServer } from 'vite';

import { build as viteBuild } from './build';
Expand Down
47 changes: 47 additions & 0 deletions code/builders/builder-vite/src/optimizeDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,58 @@ const INCLUDE_CANDIDATES = [
'@emotion/core',
'@emotion/is-prop-valid',
'@emotion/styled',
'@storybook/addon-a11y/preview',
'@storybook/addon-backgrounds/preview',
'@storybook/addon-designs/blocks',
'@storybook/addon-docs/preview',
'@storybook/addon-essentials/actions/preview',
'@storybook/addon-essentials/actions/preview',
'@storybook/addon-essentials/backgrounds/preview',
'@storybook/addon-essentials/docs/preview',
'@storybook/addon-essentials/highlight/preview',
'@storybook/addon-essentials/measure/preview',
'@storybook/addon-essentials/outline/preview',
'@storybook/addon-essentials/viewport/preview',
'@storybook/addon-highlight/preview',
'@storybook/addon-links/preview',
'@storybook/addon-measure/preview',
'@storybook/addon-outline/preview',
'@storybook/addon-themes',
'@storybook/addon-themes/preview',
'@storybook/addon-viewport',
'@storybook/addon-viewport/preview',
'@storybook/blocks',
'@storybook/components',
'@storybook/experimental-addon-test/preview',
'@storybook/experimental-nextjs-vite/dist/preview.mjs',
'@storybook/html',
'@storybook/html/dist/entry-preview-docs.mjs',
'@storybook/html/dist/entry-preview.mjs',
'@storybook/preact',
'@storybook/preact/dist/entry-preview-docs.mjs',
'@storybook/preact/dist/entry-preview.mjs',
'@storybook/react > acorn-jsx',
'@storybook/react',
'@storybook/react/dist/entry-preview-docs.mjs',
'@storybook/react/dist/entry-preview-rsc.mjs',
'@storybook/react/dist/entry-preview.mjs',
'@storybook/svelte',
'@storybook/svelte/dist/entry-preview-docs.mjs',
'@storybook/svelte/dist/entry-preview.mjs',
'@storybook/theming',
'@storybook/vue3',
'@storybook/vue3/dist/entry-preview-docs.mjs',
'@storybook/vue3/dist/entry-preview.mjs',
'@storybook/web-components',
'@storybook/web-components/dist/entry-preview-docs.mjs',
'@storybook/web-components/dist/entry-preview.mjs',
'acorn-jsx',
'acorn-walk',
'acorn',
'airbnb-js-shims',
'ansi-to-html',
'axe-core',
'chromatic/isChromatic',
'color-convert',
'deep-object-diff',
'doctrine',
Expand Down Expand Up @@ -73,6 +115,8 @@ const INCLUDE_CANDIDATES = [
'lodash/upperFirst.js',
'lodash/upperFirst',
'memoizerific',
'mockdate',
'msw-storybook-addon',
'overlayscrollbars',
'polished',
'prettier/parser-babel',
Expand Down Expand Up @@ -100,8 +144,11 @@ const INCLUDE_CANDIDATES = [
'refractor/lang/typescript.js',
'refractor/lang/yaml.js',
'regenerator-runtime/runtime.js',
'sb-original/default-loader',
'sb-original/image-context',
'slash',
'store2',
'storybook/internal/preview/runtime',
'synchronous-promise',
'telejson',
'ts-dedent',
Expand Down
8 changes: 5 additions & 3 deletions code/builders/builder-webpack5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import prettyTime from 'pretty-hrtime';
import sirv from 'sirv';
import { corePath } from 'storybook/core-path';
import type { Configuration, Stats, StatsOptions } from 'webpack';
import webpack, { ProgressPlugin } from 'webpack';
import webpackDep, { DefinePlugin, ProgressPlugin } from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';

export * from './types';
export * from './preview/virtual-module-mapping';

export const WebpackDefinePlugin = DefinePlugin;

export const printDuration = (startTime: [number, number]) =>
prettyTime(process.hrtime(startTime))
.replace(' ms', ' milliseconds')
Expand Down Expand Up @@ -51,8 +53,8 @@ export const executor = {
get: async (options: Options) => {
const version = ((await options.presets.apply('webpackVersion')) || '5') as string;
const webpackInstance =
(await options.presets.apply<{ default: typeof webpack }>('webpackInstance'))?.default ||
webpack;
(await options.presets.apply<{ default: typeof webpackDep }>('webpackInstance'))?.default ||
webpackDep;
checkWebpackVersion({ version }, '5', 'builder-webpack5');
return webpackInstance;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ export default async (
}),
new DefinePlugin({
...stringifyProcessEnvs(envs),
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
NODE_ENV: JSON.stringify(
features?.developmentModeForBuild && isProd ? 'development' : process.env.NODE_ENV
),
}),
new ProvidePlugin({ process: require.resolve('process/browser.js') }),
isProd ? null : new HotModuleReplacementPlugin(),
Expand Down
2 changes: 1 addition & 1 deletion code/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"@storybook/csf": "0.1.12",
"better-opn": "^3.0.2",
"browser-assert": "^1.2.1",
"esbuild": "^0.18.0 || ^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || 0.24.0",
"esbuild": "^0.18.0 || ^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0",
"esbuild-register": "^3.5.0",
"jsdoc-type-pratt-parser": "^4.0.0",
"process": "^0.11.10",
Expand Down
2 changes: 2 additions & 0 deletions code/core/src/types/modules/core-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ export interface StorybookConfigRaw {
viewportStoryGlobals?: boolean;
/** Use globals & globalTypes for configuring the backgrounds addon */
backgroundsStoryGlobals?: boolean;
/** Set NODE_ENV to development in built Storybooks for better testability and debuggability */
developmentModeForBuild?: boolean;
};

build?: TestBuildConfig;
Expand Down
64 changes: 32 additions & 32 deletions code/core/template/stories/rendering.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ export const ForceRemount = {
tags: ['!test', '!vitest'],
};

let loadedLabel = 'Initial';

/**
* This story demonstrates what happens when rendering (loaders) have side effects, and can possibly
* interleave with each other Triggering multiple force remounts quickly should only result in a
* single remount in the end and the label should be 'Loaded. Click Me' at the end. If loaders are
* interleaving it would result in a label of 'Error: Interleaved loaders. Click Me' Similarly,
* changing args rapidly should only cause one rerender at a time, producing the same result.
*/
export const SlowLoader = {
parameters: {
chromatic: { disable: true },
},
loaders: [
async () => {
loadedLabel = 'Loading...';
await new Promise((resolve) => setTimeout(resolve, 1000));
loadedLabel = loadedLabel === 'Loading...' ? 'Loaded.' : 'Error: Interleaved loaders.';
return { label: loadedLabel };
},
],
decorators: [
(storyFn: any, context: any) =>
storyFn({
args: {
...context.args,
label: `${context.loaded.label} ${context.args.label}`,
},
}),
],
};

export const ChangeArgs = {
play: async ({ canvasElement, id }: PlayFunctionContext<any>) => {
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
Expand Down Expand Up @@ -74,35 +106,3 @@ export const ChangeArgs = {
await expect(button).toHaveFocus();
},
};

let loadedLabel = 'Initial';

/**
* This story demonstrates what happens when rendering (loaders) have side effects, and can possibly
* interleave with each other Triggering multiple force remounts quickly should only result in a
* single remount in the end and the label should be 'Loaded. Click Me' at the end. If loaders are
* interleaving it would result in a label of 'Error: Interleaved loaders. Click Me' Similarly,
* changing args rapidly should only cause one rerender at a time, producing the same result.
*/
export const SlowLoader = {
parameters: {
chromatic: { disable: true },
},
loaders: [
async () => {
loadedLabel = 'Loading...';
await new Promise((resolve) => setTimeout(resolve, 1000));
loadedLabel = loadedLabel === 'Loading...' ? 'Loaded.' : 'Error: Interleaved loaders.';
return { label: loadedLabel };
},
],
decorators: [
(storyFn: any, context: any) =>
storyFn({
args: {
...context.args,
label: `${context.loaded.label} ${context.args.label}`,
},
}),
],
};
2 changes: 1 addition & 1 deletion code/deprecated/node-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"exports": {
".": {
"types": "./shim.d.ts",
"module": "./shim.mjs",
"import": "./shim.mjs",
"require": "./shim.js"
},
"./package.json": "./package.json"
Expand Down
Loading

0 comments on commit 0abf3ce

Please sign in to comment.