[wp-trac] [WordPress Trac] #60263: Fluid typography: PHP division by zero error when theme.json min and max viewport widths are equal

WordPress Trac noreply at wordpress.org
Tue Jan 16 04:09:02 UTC 2024


#60263: Fluid typography: PHP division by zero error when theme.json min and max
viewport widths are equal
-------------------------+-------------------------------------------------
 Reporter:  ramonopoly   |      Owner:  (none)
     Type:  defect       |     Status:  new
  (bug)                  |
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Editor       |    Version:  trunk
 Severity:  normal       |   Keywords:  has-patch has-unit-tests gutenberg-
  Focuses:               |  merge
-------------------------+-------------------------------------------------
 When the same value is provided for min and max viewport widths in
 theme.json fluid typography config, PHP will throw a
 `DivisionByZeroError`.

 This is because fluid typography calculates the linear scale denominator
 using `minViewportWidth - maxViewportWidth`.

 See the two `1640px` values:


 {{{
 {
         "$schema": "https://schemas.wp.org/trunk/theme.json",
         "version": 2,
         "settings": {

                 "typography": {
                         "fluid": {
                                 "minFontSize": "16px",
                                 "maxViewportWidth": "1640px",
                                 "minViewportWidth": "1640px"
                         }
                 }
         }
 }
 }}}




 To avoid dividing by zero values, I propose falling back to the default
 linear scale factor of `1` when `minViewportWidth - maxViewportWidth` is
 zero or some other falsy.

 The fluid typography clamp rule needs valid max and min viewport
 constraints.

 Alternatives to this approach:

 1. We could provide a fallback from the
 [https://github.com/WordPress/gutenberg/blob/29cf213ee3a6a5ef39e768ec6de3e20873355d15/lib
 /block-supports/typography.php#L474-L474 default values] in
 gutenberg_get_typography_font_size_value(), e.g., 1600 - 320.
 2. Not calculate fluid typography values and return null.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60263>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list