Skip to content

Commit

Permalink
Add fallback empty array to prevent spread syntax error with undefine…
Browse files Browse the repository at this point in the history
…d values
  • Loading branch information
andrewserong committed Dec 6, 2021
1 parent 8c52346 commit 5af4d2e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/colors/with-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const withEditorColorPalette = () =>
const themePalette = useSetting( 'color.palette.theme' );
const defaultPalette = useSetting( 'color.palette.default' );
const allColors = useMemo(
() => [ ...userPalette, ...themePalette, ...defaultPalette ],
() => [
...( userPalette || [] ),
...( themePalette || [] ),
...( defaultPalette || [] ),
],
[ userPalette, themePalette, defaultPalette ]
);
return <WrappedComponent { ...props } colors={ allColors } />;
Expand Down
15 changes: 13 additions & 2 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ export function ColorEdit( props ) {
const themePalette = useSetting( 'color.palette.theme' );
const defaultPalette = useSetting( 'color.palette.default' );
const allSolids = useMemo(
() => [ ...userPalette, ...themePalette, ...defaultPalette ],
() => [
...( userPalette || [] ),
...( themePalette || [] ),
...( defaultPalette || [] ),
],
[ userPalette, themePalette, defaultPalette ]
);
const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
Expand Down Expand Up @@ -442,7 +446,14 @@ export const withColorPaletteStyles = createHigherOrderComponent(
const userPalette = useSetting( 'color.palette.custom' ) || [];
const themePalette = useSetting( 'color.palette.theme' ) || [];
const defaultPalette = useSetting( 'color.palette.default' ) || [];
const colors = [ ...userPalette, ...themePalette, ...defaultPalette ];
const colors = useMemo(
() => [
...( userPalette || [] ),
...( themePalette || [] ),
...( defaultPalette || [] ),
],
[ userPalette, themePalette, defaultPalette ]
);
if ( ! hasColorSupport( name ) || shouldSkipSerialization( name ) ) {
return <BlockListBlock { ...props } />;
}
Expand Down
9 changes: 8 additions & 1 deletion packages/block-editor/src/hooks/use-color-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ export function useColorProps( attributes ) {
const themePalette = useSetting( 'color.palette.theme' ) || [];
const defaultPalette = useSetting( 'color.palette.default' ) || [];
const gradientsPerOrigin = useSetting( 'color.gradients' ) || EMPTY_OBJECT;
const colors = [ ...userPalette, ...themePalette, ...defaultPalette ];
const colors = useMemo(
() => [
...( userPalette || [] ),
...( themePalette || [] ),
...( defaultPalette || [] ),
],
[ userPalette, themePalette, defaultPalette ]
);
const gradients = useMemo(
() => [
...( gradientsPerOrigin?.custom || [] ),
Expand Down

0 comments on commit 5af4d2e

Please sign in to comment.