From f6555880c576b0d5d0210ab56cdc62fb0bfbdb36 Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Thu, 26 Dec 2024 15:04:34 +0530 Subject: [PATCH] fix: canvas zooms in when pattern inserter closed after opening block inserter once --- .../block-editor/src/components/inserter/menu.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/inserter/menu.js b/packages/block-editor/src/components/inserter/menu.js index e7461809b47db4..e3b0aa3d44aaee 100644 --- a/packages/block-editor/src/components/inserter/menu.js +++ b/packages/block-editor/src/components/inserter/menu.js @@ -12,6 +12,7 @@ import { useCallback, useMemo, useRef, + useEffect, useLayoutEffect, } from '@wordpress/element'; import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components'; @@ -74,11 +75,6 @@ function InserterMenu( useState( null ); const isLargeViewport = useViewportMatch( 'large' ); - const selectedTab = useSelect( ( select ) => - select( blockEditorStore ).getSelectedTab() - ); - const { setSelectedTab } = useDispatch( blockEditorStore ); - function getInitialTab() { if ( __experimentalInitialTab ) { return __experimentalInitialTab; @@ -91,9 +87,13 @@ function InserterMenu( return 'blocks'; } - useLayoutEffect( () => { - setSelectedTab( getInitialTab() ); - }, [] ); + const [ selectedTab, setSelectedTab ] = useState( getInitialTab() ); + const { setSelectedTab: setInserterSelectedTab } = + useDispatch( blockEditorStore ); + + useEffect( () => { + setInserterSelectedTab( selectedTab ); + }, [ selectedTab, setInserterSelectedTab ] ); const shouldUseZoomOut = hasSectionRootClientId &&