diff --git a/CHANGELOG.md b/CHANGELOG.md index 14dc6a61ecc7..256196a7e79a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 10.2.12 + +- Core: Sanitize inputs for save from controls - [#33868](https://github.com/storybookjs/storybook/pull/33868), thanks @valentinpalkovic! +- Telemetry: Add project age - [#33910](https://github.com/storybookjs/storybook/pull/33910), thanks @shilman! +- Webpack: Improve performance of module-mocking plugins - [#33169](https://github.com/storybookjs/storybook/pull/33169), thanks @valentinpalkovic! + ## 10.2.11 - Addon-Vitest: Fix postinstall a11y installation - [#33888](https://github.com/storybookjs/storybook/pull/33888), thanks @valentinpalkovic! diff --git a/code/builders/builder-webpack5/src/plugins/webpack-inject-mocker-runtime-plugin.ts b/code/builders/builder-webpack5/src/plugins/webpack-inject-mocker-runtime-plugin.ts index da843d1cd782..84e0fcdfdac6 100644 --- a/code/builders/builder-webpack5/src/plugins/webpack-inject-mocker-runtime-plugin.ts +++ b/code/builders/builder-webpack5/src/plugins/webpack-inject-mocker-runtime-plugin.ts @@ -13,6 +13,7 @@ const PLUGIN_NAME = 'WebpackInjectMockerRuntimePlugin'; * Storybook preview bundle, are executed. */ export class WebpackInjectMockerRuntimePlugin { + private cachedRuntime: string | null = null; // We need to lazy-require HtmlWebpackPlugin because it's an optional peer dependency. private getHtmlWebpackPlugin(compiler: Compiler): typeof HtmlWebpackPlugin | null { try { @@ -52,20 +53,23 @@ export class WebpackInjectMockerRuntimePlugin { PLUGIN_NAME, (data, cb) => { try { - const runtimeScriptContent = getMockerRuntime(); + const runtimeScriptContent = + this.cachedRuntime ?? (this.cachedRuntime = getMockerRuntime()); const runtimeAssetName = 'mocker-runtime-injected.js'; // Use the documented `emitAsset` method to add the pre-bundled runtime script // to the compilation's assets. This is the standard Webpack way. - compilation.emitAsset( - runtimeAssetName, - new compiler.webpack.sources.RawSource(runtimeScriptContent) - ); + if (!compilation.getAsset(runtimeAssetName)) { + compilation.emitAsset( + runtimeAssetName, + new compiler.webpack.sources.RawSource(runtimeScriptContent) + ); + data.assets.js.unshift(runtimeAssetName); + } - // Prepend the name of our new asset to the list of JavaScript files. + // Prepend the name of our new asset to the list of JavaScript files, once. // HtmlWebpackPlugin will automatically create a