@@ -68,9 +68,10 @@ function useFitText( { fitText, name, clientId } ) {
6868 const hasFitTextSupport = hasBlockSupport ( name , FIT_TEXT_SUPPORT_KEY ) ;
6969 const blockElement = useBlockElement ( clientId ) ;
7070
71- // Monitor block attribute changes, and parent changes.
71+ // Monitor block attribute changes, parent changes, and block mode .
7272 // Any attribute or parent change may change the available space.
73- const { blockAttributes, parentId } = useSelect (
73+ // Block mode is needed to disable fit text when in HTML editing mode.
74+ const { blockAttributes, parentId, blockMode } = useSelect (
7475 ( select ) => {
7576 if ( ! clientId || ! hasFitTextSupport || ! fitText ) {
7677 return EMPTY_OBJECT ;
@@ -80,6 +81,7 @@ function useFitText( { fitText, name, clientId } ) {
8081 select ( blockEditorStore ) . getBlockAttributes ( clientId ) ,
8182 parentId :
8283 select ( blockEditorStore ) . getBlockRootClientId ( clientId ) ,
84+ blockMode : select ( blockEditorStore ) . getBlockMode ( clientId ) ,
8385 } ;
8486 } ,
8587 [ clientId , hasFitTextSupport , fitText ]
@@ -118,7 +120,8 @@ function useFitText( { fitText, name, clientId } ) {
118120 ! fitText ||
119121 ! blockElement ||
120122 ! clientId ||
121- ! hasFitTextSupport
123+ ! hasFitTextSupport ||
124+ blockMode === 'html'
122125 ) {
123126 return ;
124127 }
@@ -189,11 +192,17 @@ function useFitText( { fitText, name, clientId } ) {
189192 applyFitText ,
190193 blockElement ,
191194 hasFitTextSupport ,
195+ blockMode ,
192196 ] ) ;
193197
194198 // Trigger fit text recalculation when content changes
195199 useEffect ( ( ) => {
196- if ( fitText && blockElement && hasFitTextSupport ) {
200+ if (
201+ fitText &&
202+ blockElement &&
203+ hasFitTextSupport &&
204+ blockMode !== 'html'
205+ ) {
197206 // Wait for next frame to ensure DOM has updated after content changes
198207 const frameId = window . requestAnimationFrame ( ( ) => {
199208 if ( blockElement ) {
@@ -209,6 +218,7 @@ function useFitText( { fitText, name, clientId } ) {
209218 applyFitText ,
210219 blockElement ,
211220 hasFitTextSupport ,
221+ blockMode ,
212222 ] ) ;
213223
214224 return { fontSize } ;
0 commit comments