Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't grab bookmarks until the end
  • Loading branch information
SantosGuillamot committed Jul 1, 2024
commit afbf38cd0f786022d8ef0c74ddb55ab371ff943b
8 changes: 5 additions & 3 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ private function replace_html( string $block_content, string $attribute_name, $s
$bindings_processor = new class( $block_content, WP_HTML_Processor::CONSTRUCTOR_UNLOCK_CODE ) extends WP_HTML_Processor {
Copy link
Member

Choose a reason for hiding this comment

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

this is an interesting side-effect of that choice. I think we should rename that constant to something scarier, like what its value is.

I kind of like that it makes anonymous classes stand out more.

Copy link
Member

Choose a reason for hiding this comment

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

@sirreal I think this is a really good example of a part of the HTML Processor we're going to have to improve.

not only is the unlock code ugly here (ugly, because it shouts how this is work-around territory), but also by calling the constructor directly we bypass setting up the context node and the HTML node. in effect, this is starting as a full parser instead of a fragment parser.

I wonder how we can better allow subclassing without this hassle and risk.

public function set_inner_text( $new_content ) {
$tag_name = $this->get_tag();
// Get position of the opener tag.
// Set position of the opener tag.
$this->set_bookmark( 'opener_tag' );
$opener_tag_bookmark = $this->bookmarks['_opener_tag'];

// Visit the closing tag.
if ( ! $this->next_tag(
Expand All @@ -352,8 +351,11 @@ public function set_inner_text( $new_content ) {
return null;
}

// Get position of the closer tag.
// Set position of the closer tag.
$this->set_bookmark( 'closer_tag' );

// Get opener and closer tag bookmarks.
$opener_tag_bookmark = $this->bookmarks['_opener_tag'];
$closer_tag_bookmark = $this->bookmarks['_closer_tag'];

// Appends the new content.
Expand Down