From 4bbba2769ba09b6fd705c720ad3e3492fe81cb1f Mon Sep 17 00:00:00 2001 From: Lene Gadewoll Date: Tue, 2 Jul 2024 18:17:37 +0200 Subject: [PATCH] fix: adds an early return on defaultprops retrieval - this prevents potential errors around fewer/more hooks being rendered --- .../eui/.storybook/addons/code-snippet/decorators/utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eui/.storybook/addons/code-snippet/decorators/utils.ts b/packages/eui/.storybook/addons/code-snippet/decorators/utils.ts index c4bc080ddba9..8bb378ab3f45 100644 --- a/packages/eui/.storybook/addons/code-snippet/decorators/utils.ts +++ b/packages/eui/.storybook/addons/code-snippet/decorators/utils.ts @@ -330,15 +330,17 @@ export const getDefaultPropsfromDocgenInfo = ( ): Record | undefined => { if (typeof component.type === 'string') return; + if (!isStoryComponent(component, context)) return; + // determine the story element first // this is required because the story might be wrapped and // only the story element has the required docgenInfo - let storyComponent: ReactElementWithDocgenInfo | undefined = + const storyComponent: ReactElementWithDocgenInfo | undefined = getStoryComponent(component, context); if (!storyComponent) return; - let propsInfo = + const propsInfo = isEmotionComponent(storyComponent) && typeof storyComponent.props?.[EMOTION_TYPE_KEY] !== 'string' ? storyComponent.props?.[EMOTION_TYPE_KEY]?.__docgenInfo.props