Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in site-editor when presets are null #30144

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions packages/edit-site/src/components/editor/global-styles-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ function getBlockPresetsDeclarations( blockPresets = {} ) {
PRESET_METADATA,
( declarations, { path, valueKey, cssVarInfix } ) => {
const preset = get( blockPresets, path, [] );
preset.forEach( ( value ) => {
declarations.push(
`--wp--preset--${ cssVarInfix }--${ value.slug }: ${ value[ valueKey ] }`
);
} );
if ( preset ) {
Copy link
Member

@gziolo gziolo Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting. It looks like get doesn't add enough safety because preset is defined but set to some falsy value.

preset.forEach( ( value ) => {
declarations.push(
`--wp--preset--${ cssVarInfix }--${ value.slug }: ${ value[ valueKey ] }`
);
} );
}
return declarations;
},
[]
Expand All @@ -66,13 +68,15 @@ function getBlockPresetClasses( blockSelector, blockPresets = {} ) {
}
classes.forEach( ( { classSuffix, propertyName } ) => {
const presets = get( blockPresets, path, [] );
presets.forEach( ( preset ) => {
const slug = preset.slug;
const value = preset[ valueKey ];
const classSelectorToUse = `.has-${ slug }-${ classSuffix }`;
const selectorToUse = `${ blockSelector }${ classSelectorToUse }`;
declarations += `${ selectorToUse } {${ propertyName }: ${ value };}`;
} );
if ( presets ) {
presets.forEach( ( preset ) => {
const slug = preset.slug;
const value = preset[ valueKey ];
const classSelectorToUse = `.has-${ slug }-${ classSuffix }`;
const selectorToUse = `${ blockSelector }${ classSelectorToUse }`;
declarations += `${ selectorToUse } {${ propertyName }: ${ value };}`;
} );
}
} );
return declarations;
},
Expand Down