From b2ad07ee999899339e782a88e2a5859a23536c60 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Mon, 16 Dec 2024 22:23:18 +0100 Subject: [PATCH 1/2] Prevent addon state from absolutely bombing render performance --- code/core/src/manager-api/root.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/code/core/src/manager-api/root.tsx b/code/core/src/manager-api/root.tsx index c2784329ab8f..8d5c501607d6 100644 --- a/code/core/src/manager-api/root.tsx +++ b/code/core/src/manager-api/root.tsx @@ -41,7 +41,7 @@ import { STORY_CHANGED, } from '@storybook/core/core-events'; -import { mergeWith } from 'es-toolkit'; +import { isEqual } from 'es-toolkit'; import { createContext } from './context'; import getInitialState from './initial-state'; @@ -218,14 +218,17 @@ class ManagerProvider extends Component { return null!; } - shouldComponentUpdate(nextProps: ManagerProviderProps, nextState: State): boolean { - const prevState = this.state; + shouldComponentUpdate( + nextProps: ManagerProviderProps, + { addons: _, ...nextState }: State + ): boolean { const prevProps = this.props; + const { addons: __, ...prevState } = this.state; - if (prevState !== nextState) { + if (prevProps.path !== nextProps.path) { return true; } - if (prevProps.path !== nextProps.path) { + if (!isEqual(prevState, nextState)) { return true; } return false; From 8e2e08f9efa111a419f5e51956073341dfe991e5 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Wed, 18 Dec 2024 14:49:27 +0100 Subject: [PATCH 2/2] Don't ignore addon state as it may be relevant --- code/core/src/manager-api/root.tsx | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/code/core/src/manager-api/root.tsx b/code/core/src/manager-api/root.tsx index 8d5c501607d6..0889a560c8a0 100644 --- a/code/core/src/manager-api/root.tsx +++ b/code/core/src/manager-api/root.tsx @@ -218,20 +218,10 @@ class ManagerProvider extends Component { return null!; } - shouldComponentUpdate( - nextProps: ManagerProviderProps, - { addons: _, ...nextState }: State - ): boolean { + shouldComponentUpdate(nextProps: ManagerProviderProps, nextState: State): boolean { const prevProps = this.props; - const { addons: __, ...prevState } = this.state; - - if (prevProps.path !== nextProps.path) { - return true; - } - if (!isEqual(prevState, nextState)) { - return true; - } - return false; + const prevState = this.state; + return prevProps.path !== nextProps.path || !isEqual(prevState, nextState); } initModules = () => {