Skip to content

Commit

Permalink
Update useGlobalStylesOutput to use SVGs strings in styles instead of…
Browse files Browse the repository at this point in the history
… SVG elements in filterSvgs
  • Loading branch information
Alex Lende committed Mar 24, 2023
1 parent f426d62 commit 0dabaf4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
store as blocksStore,
} from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
import { useContext, useMemo } from '@wordpress/element';
import { renderToString, useContext, useMemo } from '@wordpress/element';
import { getCSSRules } from '@wordpress/style-engine';

/**
Expand Down Expand Up @@ -144,13 +144,16 @@ function getPresetsSvgFilters( blockPresets = {} ) {
return [ 'default', 'theme' ]
.filter( ( origin ) => presetByOrigin[ origin ] )
.flatMap( ( origin ) =>
presetByOrigin[ origin ].map( ( preset ) => (
<PresetDuotoneFilter
preset={ preset }
key={ preset.slug }
/>
) )
);
presetByOrigin[ origin ].map( ( preset ) =>
renderToString(
<PresetDuotoneFilter
preset={ preset }
key={ preset.slug }
/>
)
)
)
.join( '' );
} );
}

Expand Down Expand Up @@ -1049,9 +1052,9 @@ export function useGlobalStylesOutput() {
hasFallbackGapSupport,
disableLayoutStyles
);
const svgs = toSvgFilters( mergedConfig, blockSelectors );

const filters = toSvgFilters( mergedConfig, blockSelectors );
const stylesheets = [
const styles = [
{
css: customProperties,
isGlobalStyles: true,
Expand All @@ -1065,6 +1068,10 @@ export function useGlobalStylesOutput() {
css: mergedConfig.styles.css ?? '',
isGlobalStyles: true,
},
{
assets: svgs,
isGlobalStyles: true,
},
];

// Loop through the blocks to check if there are custom CSS values.
Expand All @@ -1073,7 +1080,7 @@ export function useGlobalStylesOutput() {
getBlockTypes().forEach( ( blockType ) => {
if ( mergedConfig.styles.blocks[ blockType.name ]?.css ) {
const selector = blockSelectors[ blockType.name ].selector;
stylesheets.push( {
styles.push( {
css: processCSSNesting(
mergedConfig.styles.blocks[ blockType.name ]?.css,
selector
Expand All @@ -1083,7 +1090,7 @@ export function useGlobalStylesOutput() {
}
} );

return [ stylesheets, mergedConfig.settings, filters ];
return [ styles, mergedConfig.settings ];
}, [
hasBlockGapSupport,
hasFallbackGapSupport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { unlock } from '../../private-apis';
const { useGlobalStylesOutput } = unlock( blockEditorPrivateApis );

function useGlobalStylesRenderer() {
const [ styles, settings, svgFilters ] = useGlobalStylesOutput();
const [ styles, settings ] = useGlobalStylesOutput();
const { getSettings } = useSelect( editSiteStore );
const { updateSettings } = useDispatch( editSiteStore );

Expand All @@ -30,7 +30,6 @@ function useGlobalStylesRenderer() {
updateSettings( {
...currentStoreSettings,
styles: [ ...nonGlobalStyles, ...styles ],
svgFilters,
__experimentalFeatures: settings,
} );
}, [ styles, settings ] );
Expand Down

0 comments on commit 0dabaf4

Please sign in to comment.