Description
When "Fit text" is enabled (Typography > Fit text toggle) on a Paragraph
or Heading block placed inside a Media & Text block, the text does not
scale correctly in Firefox. It renders correctly in Chrome, Edge, Brave,
and Safari.
The text either overflows the content area or renders at a size that
doesn't fit the container — on both frontend and backend (editor).
This appears to be the CSS Grid counterpart of the flex container issue
fixed in #73652. That PR fixed fitText inside flex containers, but the
Media & Text block uses a CSS Grid layout (grid-template-columns: 50% 1fr),
and the same class of problem occurs here — the fitText algorithm
miscalculates the available width inside the 1fr grid column in Firefox.
I also attempted the CSS-only fix of adding min-width: 0 to
.wp-block-media-text__content (which is a standard fix for grid item
intrinsic sizing in Firefox), but this did not resolve the issue. The
problem appears to be in how the fitText JavaScript reads the container
dimensions inside a CSS Grid context in Firefox, not just in how Firefox
resolves min-width: auto.
Step-by-step reproduction instructions
- Open Firefox (tested with v147.0.4 and Developer Edition v148.0b15)
- Create a new post
- Add a Media & Text block
- Add an image to the media side
- In the text content area, add a Paragraph or Heading block
- Enable "Fit text" under Typography settings for that block
- Observe: the text does not scale to fit the content area properly
Now open the same page in Chrome — the text scales correctly.
Expected behavior
The text should scale to fit the available width of the
.wp-block-media-text__content area, just like it does in Chrome/Edge/Safari.
Actual behavior
In Firefox, the text either overflows the content column or renders at an
incorrect (too large) size. Problem occurs on both the frontend and
within the block editor.
Environment info
- WordPress 6.9.1
- Firefox 147.0.4 (64-bit) and Firefox Developer 148.0b15 (64-bit)
- Theme: Twenty Twenty-Five (also reproduced with Playground default)
- Plugins: None
- Works correctly in Chrome, Edge, Brave, Safari
Analysis
The Media & Text block uses:
.wp-block-media-text {
grid-template-columns: 50% 1fr;
}
The content area sits in the 1fr column. The fitText algorithm uses a
binary search that compares scrollWidth/scrollHeight against
clientWidth/clientHeight to find the maximum font size that fits.
Firefox reports different values for scrollWidth on elements inside
1fr grid tracks compared to Chromium browsers — particularly when the
content is being dynamically resized by the fitText algorithm. This causes
the binary search to converge on the wrong font size.
PR #73652 fixed a similar issue for flex containers by adjusting how
the fitText code handles nested flex layouts. The same approach likely
needs to be extended to handle CSS Grid containers like Media & Text.
A CSS-only fix (min-width: 0 on .wp-block-media-text__content) was
tested and did not resolve the issue, confirming this requires a
JavaScript-level fix in the fitText measurement logic.
Related
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
Description
When "Fit text" is enabled (Typography > Fit text toggle) on a Paragraph
or Heading block placed inside a Media & Text block, the text does not
scale correctly in Firefox. It renders correctly in Chrome, Edge, Brave,
and Safari.
The text either overflows the content area or renders at a size that
doesn't fit the container — on both frontend and backend (editor).
This appears to be the CSS Grid counterpart of the flex container issue
fixed in #73652. That PR fixed fitText inside flex containers, but the
Media & Text block uses a CSS Grid layout (
grid-template-columns: 50% 1fr),and the same class of problem occurs here — the fitText algorithm
miscalculates the available width inside the
1frgrid column in Firefox.I also attempted the CSS-only fix of adding
min-width: 0to.wp-block-media-text__content(which is a standard fix for grid itemintrinsic sizing in Firefox), but this did not resolve the issue. The
problem appears to be in how the fitText JavaScript reads the container
dimensions inside a CSS Grid context in Firefox, not just in how Firefox
resolves
min-width: auto.Step-by-step reproduction instructions
Now open the same page in Chrome — the text scales correctly.
Expected behavior
The text should scale to fit the available width of the
.wp-block-media-text__contentarea, just like it does in Chrome/Edge/Safari.Actual behavior
In Firefox, the text either overflows the content column or renders at an
incorrect (too large) size. Problem occurs on both the frontend and
within the block editor.
Environment info
Analysis
The Media & Text block uses:
The content area sits in the
1frcolumn. The fitText algorithm uses abinary search that compares
scrollWidth/scrollHeightagainstclientWidth/clientHeightto find the maximum font size that fits.Firefox reports different values for
scrollWidthon elements inside1frgrid tracks compared to Chromium browsers — particularly when thecontent is being dynamically resized by the fitText algorithm. This causes
the binary search to converge on the wrong font size.
PR #73652 fixed a similar issue for flex containers by adjusting how
the fitText code handles nested flex layouts. The same approach likely
needs to be extended to handle CSS Grid containers like Media & Text.
A CSS-only fix (
min-width: 0on.wp-block-media-text__content) wastested and did not resolve the issue, confirming this requires a
JavaScript-level fix in the fitText measurement logic.
Related
(backported to 6.9.1, but doesn't cover CSS Grid)
padding is not a percentage (identified the
1frwidth issue)https://core.trac.wordpress.org/ticket/64709
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.