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

Site Editor: Fix Global Styles outdated output #59628

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1192,34 +1192,32 @@ export function useGlobalStylesOutputWithConfig( mergedConfig = {} ) {

const isTemplate = blockContext?.templateSlug !== undefined;

const getBlockStyles = useSelect( ( select ) => {
return select( blocksStore ).getBlockStyles;
}, [] );
const { getBlockStyles } = useSelect( blocksStore );

return useMemo( () => {
if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
return [];
}
mergedConfig = updateConfigWithSeparator( mergedConfig );
const updatedConfig = updateConfigWithSeparator( mergedConfig );

const blockSelectors = getBlockSelectors(
getBlockTypes(),
getBlockStyles
);

const customProperties = toCustomProperties(
mergedConfig,
updatedConfig,
blockSelectors
);
const globalStyles = toStyles(
mergedConfig,
updatedConfig,
blockSelectors,
hasBlockGapSupport,
hasFallbackGapSupport,
disableLayoutStyles,
isTemplate
);
const svgs = toSvgFilters( mergedConfig, blockSelectors );
const svgs = toSvgFilters( updatedConfig, blockSelectors );

const styles = [
{
Expand All @@ -1232,7 +1230,7 @@ export function useGlobalStylesOutputWithConfig( mergedConfig = {} ) {
},
// Load custom CSS in own stylesheet so that any invalid CSS entered in the input won't break all the global styles in the editor.
{
css: mergedConfig.styles.css ?? '',
css: updatedConfig.styles.css ?? '',
isGlobalStyles: true,
},
{
Expand All @@ -1246,24 +1244,26 @@ export function useGlobalStylesOutputWithConfig( mergedConfig = {} ) {
// If there are, get the block selector and push the selector together with
// the CSS value to the 'stylesheets' array.
getBlockTypes().forEach( ( blockType ) => {
if ( mergedConfig.styles.blocks[ blockType.name ]?.css ) {
if ( updatedConfig.styles.blocks[ blockType.name ]?.css ) {
const selector = blockSelectors[ blockType.name ].selector;
styles.push( {
css: processCSSNesting(
mergedConfig.styles.blocks[ blockType.name ]?.css,
updatedConfig.styles.blocks[ blockType.name ]?.css,
selector
),
isGlobalStyles: true,
} );
}
} );

return [ styles, mergedConfig.settings ];
return [ styles, updatedConfig.settings ];
}, [
hasBlockGapSupport,
hasFallbackGapSupport,
mergedConfig,
disableLayoutStyles,
isTemplate,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this line is the fix here. I did some additional cleanup to the hook though.

getBlockStyles,
] );
}

Expand Down