@@ -11,6 +11,8 @@ import {
1111 __experimentalToolsPanelItem as ToolsPanelItem ,
1212} from '@wordpress/components' ;
1313
14+ const EMPTY_OBJECT = { } ;
15+
1416/**
1517 * Internal dependencies
1618 */
@@ -62,14 +64,19 @@ function useFitText( { fitText, name, clientId } ) {
6264 const hasFitTextSupport = hasBlockSupport ( name , FIT_TEXT_SUPPORT_KEY ) ;
6365 const blockElement = useBlockElement ( clientId ) ;
6466
65- // Monitor block attribute changes
66- // Any attribute may change the available space.
67- const blockAttributes = useSelect (
67+ // Monitor block attribute changes, and parent changes.
68+ // Any attribute or parent change may change the available space.
69+ const { blockAttributes, parentId } = useSelect (
6870 ( select ) => {
6971 if ( ! clientId || ! hasFitTextSupport || ! fitText ) {
70- return ;
72+ return EMPTY_OBJECT ;
7173 }
72- return select ( blockEditorStore ) . getBlockAttributes ( clientId ) ;
74+ return {
75+ blockAttributes :
76+ select ( blockEditorStore ) . getBlockAttributes ( clientId ) ,
77+ parentId :
78+ select ( blockEditorStore ) . getBlockRootClientId ( clientId ) ,
79+ } ;
7380 } ,
7481 [ clientId , hasFitTextSupport , fitText ]
7582 ) ;
@@ -143,6 +150,7 @@ function useFitText( { fitText, name, clientId } ) {
143150 if ( window . ResizeObserver && currentElement . parentElement ) {
144151 resizeObserver = new window . ResizeObserver ( applyFitText ) ;
145152 resizeObserver . observe ( currentElement . parentElement ) ;
153+ resizeObserver . observe ( currentElement ) ;
146154 }
147155
148156 // Cleanup function
@@ -169,7 +177,14 @@ function useFitText( { fitText, name, clientId } ) {
169177 styleElement . remove ( ) ;
170178 }
171179 } ;
172- } , [ fitText , clientId , applyFitText , blockElement , hasFitTextSupport ] ) ;
180+ } , [
181+ fitText ,
182+ clientId ,
183+ parentId ,
184+ applyFitText ,
185+ blockElement ,
186+ hasFitTextSupport ,
187+ ] ) ;
173188
174189 // Trigger fit text recalculation when content changes
175190 useEffect ( ( ) => {
0 commit comments