-
Notifications
You must be signed in to change notification settings - Fork 60
Fix: Sync fluid typography size with fluid.max (#789) #796
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
base: trunk
Are you sure you want to change the base?
Fix: Sync fluid typography size with fluid.max (#789) #796
Conversation
|
hey @scruffian i got the info about from @henriqueiamarino to review my prs |
|
@scruffian any updates ? |
|
@scruffian please also check this pr 😢 |
|
I think this should be fixed in the Gutenberg repo, not in Create Block Theme. |
|
@scruffian Thanks for the review! I understand this ideally belongs in Gutenberg core. However, I'd like to suggest keeping this as a temporary workaround in Create Block Theme while we report and wait for the fix upstream in Gutenberg. This way, CBT users won't be affected by the stale size values until Gutenberg core fixes it. My proposal:
This benefits both projects - CBT users get a fix now, and Gutenberg gets the proper fix long-term. What do you think? I can handle opening the Gutenberg issue if you approve. |
|
@scruffian any suggestions or updates ? |
I agree with this.
Does this actually cause any problems? |
|
I don't think it will take a long time to fix in Gutenberg. It would be better to put the fix there than to patch it in CBT, which would then mean there would be no pressure to fix it in Gutenberg! I'm happy to review a Gutenberg PR. |
Fix: Sync fluid typography size with fluid.max
Summary
Fixes a bug where the
sizeproperty in theme.json would retain its old value when editing Custom Fluid Typography in the Site Editor. Thefluid.minandfluid.maxvalues would update correctly, but thesizeproperty (which represents the maximum fluid size fallback) would remain stale.Fixes
Changes
includes/create-theme/theme-fluid-typography.php (new file)
CBT_Theme_Fluid_Typographyclass that syncs thesizeproperty withfluid.maxwhenever fluid typography settings are updated.rest_pre_insert_wp_global_stylesfilter to intercept global styles before they're saved.sizeto matchfluid.maxfor any font size with fluid settings.includes/class-create-block-theme-api.php
theme-fluid-typography.phpfile.tests/test-fluid-typography.php (new file)
Test_Create_Block_Theme_Fluid_Typographytest class with 5 unit tests:test_sync_fluid_typography_sizes()- Verifies fluid sizes are synced while non-fluid remain unchanged.test_sync_global_styles_fluid_typography()- Verifies the REST filter works correctly.test_sync_with_no_typography()- Verifies handling of missing typography.test_sync_with_no_font_sizes()- Verifies handling of missing fontSizes.test_sync_global_styles_with_invalid_json()- Verifies graceful error handling.Rationale
When editing Custom Fluid Typography in the Site Editor (Styles → Typography), WordPress updates the global styles JSON. However, the
sizeproperty (which serves as a fallback for the maximum fluid size) wasn't being updated to match the newfluid.maxvalue. This resulted in inconsistent typography definitions where the fluid values were current but the fallback size was stale.The fix intercepts the global styles save operation and automatically syncs
sizewithfluid.maxfor any font size that has fluid settings defined.Risk/Compatibility
rest_pre_insert_wp_global_styles) which has been available since WordPress 5.9.Test Coverage
fluid.maxvalueBehavior After Fix
Before
{ "fontSizes": [ { "slug": "custom-fluid", "name": "Custom Fluid", "fluid": { "min": "1.5rem", "max": "5.63rem" }, "size": "3rem" } ] }After
{ "fontSizes": [ { "slug": "custom-fluid", "name": "Custom Fluid", "fluid": { "min": "1.5rem", "max": "5.63rem" }, "size": "5.63rem" } ] }