From 2ebae5de6e9ed352a8f2cc191969c5efcc6d2b33 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Fri, 6 Mar 2026 01:35:49 +0900 Subject: [PATCH] Storybook: Fix crash when resetting global toolbar selections --- storybook/decorators/with-global-css.jsx | 2 +- storybook/decorators/with-rtl.jsx | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/storybook/decorators/with-global-css.jsx b/storybook/decorators/with-global-css.jsx index d053c03c7b1a5e..6ab8a128319895 100644 --- a/storybook/decorators/with-global-css.jsx +++ b/storybook/decorators/with-global-css.jsx @@ -40,7 +40,7 @@ const config = { export const WithGlobalCSS = ( Story, context ) => { const { lazyStyles, externalStyles, classes } = - config[ context.globals.css ]; + config[ context.globals.css ] ?? config.none; useEffect( () => { const style = document.createElement( 'style' ); diff --git a/storybook/decorators/with-rtl.jsx b/storybook/decorators/with-rtl.jsx index ae1e594c4c38b9..67fca5db16ad5e 100644 --- a/storybook/decorators/with-rtl.jsx +++ b/storybook/decorators/with-rtl.jsx @@ -18,6 +18,10 @@ export const WithRTL = ( Story, context ) => { const [ rerenderKey, setRerenderKey ] = useState( 0 ); const ref = useRef(); + const direction = [ 'ltr', 'rtl' ].includes( context.globals.direction ) + ? context.globals.direction + : 'ltr'; + useEffect( () => { // Override the return value of i18n.isRTL() addFilter( @@ -25,7 +29,7 @@ export const WithRTL = ( Story, context ) => { 'storybook', ( translation, text, _context ) => { if ( text === 'ltr' && _context === 'text direction' ) { - return context.globals.direction; + return direction; } return translation; } @@ -33,20 +37,20 @@ export const WithRTL = ( Story, context ) => { ref.current.ownerDocument.documentElement.setAttribute( 'dir', - context.globals.direction + direction ); setRerenderKey( ( prevValue ) => prevValue + 1 ); return () => removeFilter( 'i18n.gettext_with_context', 'storybook' ); - }, [ context.globals.direction ] ); + }, [ direction ] ); useLayoutEffect( () => { const stylesToUse = []; CONFIG.forEach( ( item ) => { if ( item.componentIdMatcher.test( context.componentId ) ) { - stylesToUse.push( ...item[ context.globals.direction ] ); + stylesToUse.push( ...item[ direction ] ); } } ); @@ -57,7 +61,7 @@ export const WithRTL = ( Story, context ) => { return () => { document.head.removeChild( style ); }; - }, [ context.componentId, context.globals.direction ] ); + }, [ context.componentId, direction ] ); return (