Global Styles: fix infinite loop in Font Style UI#73955
Conversation
|
Size Change: +56 B (0%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
243ce05 to
e1d1013
Compare
| .click(); | ||
| await page | ||
| .getByRole( 'menuitemcheckbox', { name: 'Show Appearance' } ) | ||
| .click(); |
There was a problem hiding this comment.
This removal is intentional. This E2E test verifies the behavior when an invalid font style is applied. However, in the trunk branch, the Appearance panel is hidden by default because the invalid font style is reset at render time by useEffect. Therefore, we need to explicitly open the Appearance panel here.
However, this is not ideal, as it creates an unnecessary undo history and makes the post dirty.
Perform the following in the trunk branch:
- Open the code editor and insert the following block:
<!-- wp:paragraph {"style":{"typography":{"fontStyle":"inherit"}}} -->
<p style="font-style:inherit">Hello World</p>
<!-- /wp:paragraph -->- Back to the block and save the post. The save button becomes disabled.
- Just click the block.
- The font-style disappears from the markup, and the save button becomes enabled, which means that unnecessary undo history is created.
a8ffb31bb9833772465e21496f18ea70.mp4
Meanwhile, if you check out this branch and do the same operation, the font style will not be reset when rendering, which I believe is the correct behavior.
For this reason, I think it's worth backporting this PR into a point release. |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@mikachan Thanks for the review! |
* Global Styles: fix infinite loop in Font Style UI * Fix e2e tests Co-authored-by: t-hamano <[email protected]> Co-authored-by: mikachan <[email protected]> Co-authored-by: jeffgolenski <[email protected]>
* Global Styles: fix infinite loop in Font Style UI * Fix e2e tests Co-authored-by: t-hamano <[email protected]> Co-authored-by: mikachan <[email protected]> Co-authored-by: jeffgolenski <[email protected]>
|
This PR has been backported to the |
What?
I found that changing any setting in the Typography panel would cause the UI to crash due to infinite rendering if the
fontStylefield had a value other thannormaloritalic. This problem has likely existed latent for some time, but it became apparent when #70676 added"fontStyle": "inherit"to the button element by default.This PR solves that issue by refactoring the logic to not use
useEffect.Why?
According to my research, any font style other than
normal,italic, orobliqueis not considered valid, and thefindNearestFontStyle()function returns an empty string, causing an infinite loop withinuseEffect.How?
In the first place, fallback processing should only be necessary when the font family is changed, so
useEffectis not necessary. When the font family is changed, change the logic to find a similar font style and font weight.Testing Instructions
Test the following three scenarios, all of which should crash the UI in the trunk branch:
Example 1
Activate Emptytheme and update
theme.jsonwith the following code:{ "version": 3, "settings": { "appearanceTools": true, "layout": { "contentSize": "840px", "wideSize": "1100px" } }, "styles": { "typography": { "fontStyle": "inherit" } } }Example 2
Activate Emptytheme and update
theme.jsonwith the following code:{ "version": 3, "settings": { "appearanceTools": true, "layout": { "contentSize": "840px", "wideSize": "1100px" } }, "styles": { "blocks": { "core/paragraph": { "typography": { "fontStyle": "test" } } } } }Example 3