Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
WP_HTML_Tag_Processor: Make
get_attribute
reflect attribute set viaset_attribute
, even without updating #46680WP_HTML_Tag_Processor: Make
get_attribute
reflect attribute set viaset_attribute
, even without updating #46680Changes from all commits
3dacb0e
a9afdcc
0110bcf
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
For
$this->attribute_updates
(below) it makes sense (and is easy enough) to only evaluate the updates for the attribute we're interested in (if any) and to ignore updates for all other attributes. For class name updates OTOH, we would need to replicate most of the logic fromclass_name_updates_to_attributes_updates
here, so we might as well just call that function and have classname updates "promoted" to attribute updates.cc/ @adamziel since the PHPDoc for
class_name_updates_to_attributes_updates
saysAlthough it looks okay to me to call it here?
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.
I think we need to call
$this->apply_attribute_updates()
here as well to ensure they get applied before any successiveclass
updates occur, lest we lose enqueued class name updates.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.
Ah yeah, you're right! While
class_name_updates_to_attributes_updates
does take an existingclass
attribute into account, it only looks at$this->attributes['class']
to do so -- but not into$lexical_updates
:gutenberg/lib/experimental/html/class-wp-html-tag-processor.php
Lines 1134 to 1136 in 777eaf2
So we do need to call
$this->apply_attribute_updates()
as you say (unless we wanna changeclass_name_updates_to_attributes_updates
to take$lexical_updates['class']
into account -- but I guess we'd rather not).I'll write a test case and will add a
$this->apply_attribute_updates()
call 👍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.
Note that this will change existing semantics of
add_class
andset_attribute
-- see:gutenberg/phpunit/html/wp-html-tag-processor-test.php
Lines 796 to 828 in 777eaf2
Adding the
apply_attribute_updates
call thus breaks that test (plus a few other ones, going to look into those now).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.
Considering something like this
But that will also change the semantics (two test cases -- both of which are about the
add_class
/set_attribute
interaction AFAICS).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.
do we have a reason to change the behavior? I think it's probably important to ensure that
set_attribute
andremove_attribute
updates wipe out class builder method changes, as I can reason about what it means to calladd_class
after setting theclass
attribute, but I can't reason an obvious outcome of callingadd_class
before the transactional swap ofset_attribute
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.
It is confusing 🤔 I'd like
set_attribute
to cancel anyadd_class
/remove_class
calls that happened before. I'd be fine with an undefined behavior accompanied by a warning, too, though.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.
@adamziel in my latest commit I restored that defined behavior. in other words, I'm currently thinking the change in behavior wasn't necessary and so I've removed it.
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.
Thank you for fixing the behavior @dmsnell!
FWIW, you didn't exactly revert my change 😬: The original behavior -- prior to my changes -- was that
set_attribute( 'class', 'abc' )
would "prevail" overadd_class( 'xyz' )
even if theadd_class
was called after theset_attribute
, thus resulting inclass="abc"
. This was covered by this unit test (this istrunk
!):gutenberg/phpunit/html/wp-html-tag-processor-test.php
Lines 796 to 828 in 7880f08
I came across this when I was addressing the (apparently) missing
$this->apply_attribute_updates()
call that you'd pointed out. I realized that simply adding that would introduce other problems, so I worked around those, noting that that changed the outcome of subsequentset_attribute( 'class', 'abc' )
andadd_class( 'xyz' )
calls. I did like that my change would have them result inclass="abc xyz"
, if theadd_class
was called after theset_attribute
-- I still consider this an improvement over the original behavior 👍OTOH, it meant that if
add_class( 'xyz' )
was called beforeset_attribute( 'class', 'abc' )
, it would also result inclass="abc xyz"
. I didn't pay enough attention to that consequence, which is clearly not the behavior a user would expect 👎Thanks to your change, we now have both cases behave as expected 🎉
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 clarifying @ockham - you were right, I didn't understand that this was broken before the PR. The intention was right, the implementation was wrong.