-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Server Styles - fix deduplication of style rules. #24486
Conversation
Size Change: +157 B (0%) Total Size: 1.16 MB
ℹ️ View Unchanged
|
e47c461
to
5e99bc8
Compare
Hi, @Addison-Stavlo! I took the liberty of pushing a commit (I felt I had to try it, otherwise I'd be providing vague feedback), so let me know what you think. Notes / motivation:
My only risks / open questions:
I hope pushing a commit wasn't out of line. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @mcsf!
I will try to test them a bit more thoroughly later today. Im totally fine with you pushing the commit (as long as the commits aren't squashed and I can revert to the old one if ever needed), but this looks promising!
Im generally prefer to avoid regex where available as it isn't always easily readable, but this seems simple enough.
I got the time to test this a bit more. It works great! Thanks for jumping in here @mcsf, I like how this solution works and cleans things up quite a bit. 🥳 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixing and humouring my questions!
Description
This PR fixes style rule deduplication by adding an extra step to normalize style rules to follow the same format. (Thanks @mcsf for pointing this out #23007 (comment))
Currently in server styles there are some issues with deduplication:
gutenberg/lib/block-supports/index.php
Line 78 in 5fdd5b7
At this point in the process,
$current_styles
and$styles_to_add
may or may not have different formats in spacing convention. ex:$current_styles
may be of the formone:thing;another:thing;
.$styles_to_add
may be of the formone: thing; another: thing;
.The line above acting on these inputs would output:
"one:thing;another:thing; one: thing; another:"
This happens because when these are then
explode
d by' '
, style keys in the second string are split from their values while the first string is not split at all. Additionally, since the convention in spacing is different inside the values themselves, even if these were split properly the dedupe would not work as'one:thing'
!=='one: thing'
.This PR introduces an extra step in the process to normalize the values so dedupe works as intended, and the final output of
$new_styles
would be properly deduped and of the formone: thing; another: thing;
How has this been tested?
Screenshots
Types of changes
Checklist: