Style hooks - default named values override custom saved values in editor for server side blocks. #24363
Labels
[Feature] Custom Editor Styles
Functionality for adding custom editor styles
[Type] Bug
An existing feature does not function as intended
Describe the bug
Semi-related to #24387.
Style hooks seem to be written with the intent to support default styles to be defined on the block- ex:
gutenberg/packages/block-editor/src/hooks/color.js
Lines 70 to 76 in 65258a0
However, in practice this seems to not play nice in the editor. With server side blocks, it seems that the class names for the default named styles are still applied (in the editor only) even when custom values are saved. This does not seem to be coming from the server side styles application from the
gutenberg_experimental_apply_classnames_and_styles
function in blocks.php (which is also the mechanism for delivering these styles for server side blocks on the front-end).To reproduce
Below I will explore this with a server side block, "Site Title".
attributes
in Site Title'sblock.json
file:Load the editor and add the site title block to the page. It should have the default values applied as expected:
Edit these to be custom values, save, and reload the editor. Notice that while the block has the visual custom styles applied, the settings in the sidebar pick up the default values instead:
Instead of the saved and visible font size of 56, and the two custom color values for font and background, the sidebar shows the default values instead:
Inspecting the element reveals that the classnames for these default styles are also applied to the block (in this case they are overridden by the styles applied by the saved custom values):
We would expect that they should not be added since custom values are saved.
Because of these classnames, we may notice that step 3 in other themes may result in the block also visibly having the default styles in the editor instead of the custom saved values. For instance with seedlet blocks (which adds an !important flag to some of the styles that are added by these un-wanted classnames) we see the default values loaded in the editor with the custom values on the front-end.
Editor:
Front-end:
While that last example is theme-specific, these class names should never have been added in this case in the first place.
Expected behavior
The class names of the default styles not to have been added when custom values are saved.
The text was updated successfully, but these errors were encountered: