Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Prevent FontSizePicker crash when no font size exists #68733

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

im3dabasia
Copy link
Contributor

@im3dabasia im3dabasia commented Jan 17, 2025

Closes: #62072

What?

This PR fixes a crash in the Typography panel's font size picker when no font size presets exist in theme.json. It ensures that the font size picker is disabled when no presets are available and prevents errors when setting a custom font size.

Why?

Currently, if a theme has defaultFontSizes set to false and no font size presets are defined, changing the font size causes the block to crash due to fontSizeValue?.startsWith being called on an invalid type. This PR resolves the issue by ensuring fontSizeValue is always a valid string before performing operations on it.

How?

Added a check to ensure fontSizeValue is a string before calling .startsWith().

Testing Instructions

  1. Enable the Emptytheme.
  2. Update theme.json with the following configuration(Snippet shared down below)
  3. Open the typography panel for a paragraph block.
  • ✅ The font size picker should be disabled instead of rendering an empty dropdown.
  1. Click the "Set custom size" button and enter a font size.
  • ✅ The block should no longer crash.

Code snippet for theme.json

{
   "$schema": "../../schemas/json/theme.json",
   "version": 3,
   "settings": {
      "layout": {
         "contentSize": "840px",
         "wideSize": "1100px"
      },
      "color": {
         "defaultPalette": false
      },
      "typography": {
         "defaultFontSizes": false
      }
   }
}

Screenshots or screencast

Before

Screen.Recording.2025-01-17.at.12.09.29.PM.mov

After

Screen.Recording.2025-01-17.at.12.10.47.PM.mov

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Feature] Typography Font and typography-related issues and PRs labels Jan 17, 2025
@im3dabasia im3dabasia marked this pull request as ready for review January 17, 2025 10:25
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: t-hamano <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Typography Font and typography-related issues and PRs [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typography: Font size picker crashes when no font size preset exists
2 participants