Skip to content

Commit

Permalink
Site editor: remove store subscription per block (#57995)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Jan 19, 2024
1 parent 7e604b4 commit 042f99e
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions packages/edit-site/src/hooks/push-changes-to-global-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,30 +389,36 @@ function PushChangesToGlobalStylesControl( {
);
}

const withPushChangesToGlobalStyles = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const blockEditingMode = useBlockEditingMode();
const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);
const supportsStyles = SUPPORTED_STYLES.some( ( feature ) =>
hasBlockSupport( props.name, feature )
);

return (
<>
<BlockEdit { ...props } />
{ blockEditingMode === 'default' &&
supportsStyles &&
isBlockBasedTheme && (
<InspectorAdvancedControls>
<PushChangesToGlobalStylesControl { ...props } />
</InspectorAdvancedControls>
) }
</>
);
function PushChangesToGlobalStyles( props ) {
const blockEditingMode = useBlockEditingMode();
const isBlockBasedTheme = useSelect(
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
[]
);
const supportsStyles = SUPPORTED_STYLES.some( ( feature ) =>
hasBlockSupport( props.name, feature )
);
const isDisplayed =
blockEditingMode === 'default' && supportsStyles && isBlockBasedTheme;

if ( ! isDisplayed ) {
return null;
}

return (
<InspectorAdvancedControls>
<PushChangesToGlobalStylesControl { ...props } />
</InspectorAdvancedControls>
);
}

const withPushChangesToGlobalStyles = createHigherOrderComponent(
( BlockEdit ) => ( props ) => (
<>
<BlockEdit { ...props } />
{ props.isSelected && <PushChangesToGlobalStyles { ...props } /> }
</>
)
);

addFilter(
Expand Down

1 comment on commit 042f99e

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 042f99e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7582203706
📝 Reported issues:

Please sign in to comment.