-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
theme.json: Setting block fontStyle
to inherit/initial results in error when changing block font family in the Site Editor
#68491
Comments
Hi @andersnoren, Thanks for bringing this up. After a little digging, I found out that the crash occurs due to React's reconciliation issues when updating nested style properties individually. // Current implementation
const setFontFamily = ( newValue ) => {
const slug = fontFamilies?.find(
( { fontFamily: f } ) => f === newValue
)?.slug;
onChange(
setImmutably(
value,
[ 'typography', 'fontFamily' ],
slug
? `var:preset|font-family|${ slug }`
: newValue || undefined
)
);
};
// fix
const setFontFamily = ( newValue ) => {
const slug = fontFamilies?.find(
( { fontFamily: f } ) => f === newValue
)?.slug;
const fontFamilyValue = slug ? `var:preset|font-family|${ slug }` : newValue || undefined;
onChange({
...value,
typography: {
...value?.typography,
fontFamily: fontFamilyValue
}
});
}; This fix updates the entire typography object at once instead of using setImmutably and maintains proper style inheritance Would love to hear your thoughts on this approach before proceeding with a PR. |
Do you have more details on why The P.S. Can you also share the full error you're getting in Dev mode? |
Thanks @Mamaduka for the reply, The error I am seeing is this -
|
As far as I can tell, it's this gutenberg/packages/block-editor/src/components/global-styles/typography-panel.js Lines 266 to 281 in 2c674ab
For example, excluding the dependency like this will prevent the infinite loop (Note: this is not an actual solution): diff --git a/packages/block-editor/src/components/global-styles/typography-panel.js b/packages/block-editor/src/components/global-styles/typography-panel.js
index 9bc875cdc0..940d5ce040 100644
--- a/packages/block-editor/src/components/global-styles/typography-panel.js
+++ b/packages/block-editor/src/components/global-styles/typography-panel.js
@@ -273,12 +273,7 @@ export default function TypographyPanel( {
// Reset font appearance if there are no available styles or weights.
resetFontAppearance();
}
- }, [
- nearestFontStyle,
- nearestFontWeight,
- resetFontAppearance,
- setFontAppearance,
- ] );
+ }, [] ); It looks similar to the issue reported here: https://github.com/WordPress/gutenberg/pull/61915/files#r1673421903 |
If the cause is the |
Description
In theme.json, if you set typography.fontStyle for a specific block to
inherit
orinitial
, changing the font family of that block in the Styles tab of the Site Editor crashes the editor with the error message "The editor has encountered an unexpected error.".Changing the font family of one instance of the block doesn't give the error.
Originally reported in this theme specific issue, then reproduced in Twenty Twenty-Four.
Step-by-step reproduction instructions
core/site-title
– any specific block will work though):Screenshots, screen recording, code snippet
Error message:
Environment info
WordPress 6.7.1
Without or without Gutenberg
Twenty Twenty-Four
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.
The text was updated successfully, but these errors were encountered: