Skip to content

Commit 865efdb

Browse files
committed
add cleanup for icon color type
1 parent 2c5f37d commit 865efdb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/block-components/icon/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ export const Icon = props => {
184184

185185
const ShapeComp = useMemo( () => getShapeSVG( getAttribute( 'backgroundShape' ) || 'blob1' ), [ getAttribute( 'backgroundShape' ) ] )
186186

187+
const iconColorType = getAttribute( 'iconColorType' )
188+
187189
const _icon = value || getAttribute( 'icon' )
188190
const currentIconRef = useRef( _icon )
189191
const processedIconRef = useRef( null )
@@ -204,7 +206,14 @@ export const Icon = props => {
204206

205207
// Don't use page icons for multicolor icons
206208
// because we target svg elements with the :nth-of-type() selector to apply the multicolor styles.
207-
if ( getAttribute( 'iconColorType' ) === 'multicolor' ) {
209+
if ( iconColorType === 'multicolor' ) {
210+
// Clean up if this icon was previously in the page-icons store
211+
if ( processedIconRef.current === _icon && _icon ) {
212+
dispatch( 'stackable/page-icons' ).removePageIcon( _icon )
213+
processedIconRef.current = null
214+
setIcon( _icon ) // Use the original icon directly
215+
lastIconValueRef.current = _icon
216+
}
208217
return
209218
}
210219

@@ -288,7 +297,7 @@ export const Icon = props => {
288297
lastIconValueRef.current = null
289298
}
290299
}
291-
}, [ _icon ] )
300+
}, [ _icon, iconColorType ] )
292301

293302
useEffect( () => {
294303
return () => {

0 commit comments

Comments
 (0)