From ba6cac88638912bfbb4d1a7a61270b5e146a4958 Mon Sep 17 00:00:00 2001 From: Alquen Sarmiento Date: Mon, 7 Jul 2025 10:37:30 +0800 Subject: [PATCH 1/2] fix: merge but ensure unique slug --- src/hooks/use-preset-controls.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hooks/use-preset-controls.js b/src/hooks/use-preset-controls.js index 8c35b4b9c1..d331ade6d6 100644 --- a/src/hooks/use-preset-controls.js +++ b/src/hooks/use-preset-controls.js @@ -72,7 +72,13 @@ export const usePresetControls = property => { // This happens when settings like `typography.defaultFontSizes` or `spacing.defaultSpacingSizes` // are not explicitly set to `false` in theme.json v3. if ( hasThemePresets && wpDefaultPresets && defaultSizesEnabled !== false ) { - themePresets = [ ..._themePresets, ...wpDefaultPresets ] + // Create a set for removing duplicates. + const existingSlugs = new Set( _themePresets.map( item => item.slug ) ) + + themePresets = [ + ..._themePresets, + ...wpDefaultPresets.filter( item => ! existingSlugs.has( item.slug ) ), + ] } // Get the theme/default presets if the user have one, else return the stackable presets From 9faa927b4df55f3ef1648e4301977150978b6508 Mon Sep 17 00:00:00 2001 From: Alquen Sarmiento Date: Mon, 7 Jul 2025 14:48:35 +0800 Subject: [PATCH 2/2] fix: add additional error handling --- src/hooks/use-preset-controls.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hooks/use-preset-controls.js b/src/hooks/use-preset-controls.js index d331ade6d6..8bacdde9cb 100644 --- a/src/hooks/use-preset-controls.js +++ b/src/hooks/use-preset-controls.js @@ -73,7 +73,12 @@ export const usePresetControls = property => { // are not explicitly set to `false` in theme.json v3. if ( hasThemePresets && wpDefaultPresets && defaultSizesEnabled !== false ) { // Create a set for removing duplicates. - const existingSlugs = new Set( _themePresets.map( item => item.slug ) ) + const existingSlugs = new Set() + _themePresets.forEach( item => { + if ( item && typeof item.slug === 'string' ) { + existingSlugs.add( item.slug ) + } + } ) themePresets = [ ..._themePresets,