Block Editor: Extract getElementCSSRules from useBlockProps#77327
Block Editor: Extract getElementCSSRules from useBlockProps#77327
Conversation
Extract the element CSS rules generation logic from the useMemo callback in useBlockProps into a standalone pure function. This improves readability and makes the logic independently testable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Size Change: +9 B (0%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 9eed85d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24398083795
|
MaggieCabrera
left a comment
There was a problem hiding this comment.
Makes the CSS rules logic independently testable
Should we add some tests? can we even, given that the function is not exported?
Either way I'm fine with this, it makes sense to me. Thanks for helping out here!
|
Happy for us to add tests - that can be a followup :) |
What?
Extracts the element CSS rules generation logic from the
useMemocallback inuseBlockPropsinto a standalonegetElementCSSRulesfunction inpackages/block-editor/src/hooks/style.js.Why?
The inline logic for building element CSS rules (buttons, links, headings, pseudo-selectors, sub-elements) was nested inside
useBlockProps'suseMemo. Extracting it into a named pure function:useBlockPropsHow?
getElementCSSRules( blockElementStyles, blockName, baseSelector )as a private helperuseBlockPropsnow callsgetElementCSSRulesinside itsuseMemowith the same dependency arrayTesting Instructions
🤖 Generated with Claude Code