fix: cys site assembler color palette persistence bug (#40396)

Fix the bug where sometimes switching from user defined color palettes to a pre-defined color palette won't set some colors.
This commit is contained in:
RJ 2023-09-27 16:27:04 +08:00 committed by GitHub
parent c752c60fd4
commit 858fdecc52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -29,12 +29,23 @@ export const VariationContainer = ( { variation, children } ) => {
const selectVariation = () => {
// Remove the hasCreatedOwnColors flag if the user is switching to a color palette
// hasCreatedOwnColors flag is used for visually deselecting preset color palettes if user has created their own
if (
variation.settings.color &&
user.settings.color &&
user.settings.color.hasCreatedOwnColors
user.settings.color.palette.hasCreatedOwnColors
) {
delete user.settings.color.palette.hasCreatedOwnColors;
// some color palettes don't define all the possible color options, e.g headings and captions
// if the user selects a pre-defined color palette with some own colors defined for these,
// we need to delete these user customizations as the below merge will persist them since
// the incoming variation won't have these properties defined
delete user.styles.color;
for ( const elementKey in user.styles.elements ) {
if ( user.styles.elements[ elementKey ].color ) {
delete user.styles.elements[ elementKey ].color;
}
}
}
setUserConfig( () => {

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
CYS: Fix the bug where sometimes switching from user defined color palettes to a pre-defined color palette won't set some colors.