Skip to content

Commit

Permalink
Removae old typography settings before applying new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
albarin committed Feb 8, 2024
1 parent 5cf6be7 commit 15a1b4e
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ import { isEqual, noop } from 'lodash';

const { GlobalStylesContext } = unlock( blockEditorPrivateApis );

// Removes the typography settings from the styles when the user is changing
// to a new typography variation. Otherwise, some of the user's old
// typography settings will persist making new typography settings
// depend on old ones
const resetTypographySettings = ( variation, userStyles ) => {
if ( variation.settings.typography ) {
delete userStyles.typography;
for ( const elementKey in userStyles.elements ) {
if ( userStyles.elements[ elementKey ].typography ) {
delete userStyles.elements[ elementKey ].typography;
}
}
}

return userStyles;
};

export const VariationContainer = ( { variation, children } ) => {
const { base, user, setUserConfig } = useContext( GlobalStylesContext );
const context = useMemo( () => {
Expand Down Expand Up @@ -57,7 +74,10 @@ export const VariationContainer = ( { variation, children } ) => {
user.settings,
variation.settings
),
styles: variation.styles,
styles: mergeBaseAndUserConfigs(
resetTypographySettings( variation, user.styles ),
variation.styles
),
};
} );
};
Expand Down

0 comments on commit 15a1b4e

Please sign in to comment.