Skip to content

Conversation

@sirreal
Copy link
Member

@sirreal sirreal commented Nov 21, 2024

The processor state context_node property is unused and redundant. Remove it.
The processor uses a context_node property on itself.

The $state property is private, so it should not be accessible to subclasses.
The class itself is marked with access private so should also be unused.

/**
* Core class used by the HTML processor during HTML parsing
* for managing the internal parsing state.
*
* This class is designed for internal use by the HTML processor.
*
* @since 6.4.0
*
* @access private
*
* @see WP_HTML_Processor
*/
class WP_HTML_Processor_State {

* @var WP_HTML_Processor_State
*/
private $state;

See #7348 (comment).

Trac ticket: https://core.trac.wordpress.org/ticket/62518


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@sirreal sirreal marked this pull request as ready for review November 22, 2024 09:41
@github-actions
Copy link

github-actions bot commented Nov 22, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@sirreal sirreal requested a review from gziolo November 26, 2024 16:44
@gziolo
Copy link
Member

gziolo commented Nov 27, 2024

Committed with https://core.trac.wordpress.org/changeset/59463.

@gziolo gziolo closed this Nov 27, 2024
@ockham
Copy link
Contributor

ockham commented Nov 27, 2024

Ah, thanks for that! I was actually briefly confused by this when reviewing #7348 but forgot to flag it 😊

@sirreal sirreal deleted the html-api/remove-state-context-node branch November 27, 2024 11:46
$context_node = new WP_HTML_Token(
'context-node',
$processor->state->context_node[0],
'BODY',
Copy link
Member

Choose a reason for hiding this comment

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

something seems off here: why are we hard-coding BODY as the context node? it seems like we missed this in line 301 when we added support for other contexts, whereas that line should have been updated to something like $...->context_node[0] but now we’re moving in the opposite direction…?

Copy link
Member Author

Choose a reason for hiding this comment

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

This landed before the additional context support and I believe all these lines are now stale.

In this change, the <body> context was still hard-coded above. It moved out of the ->state->context_node and into this location, while remaining hard-coded.

Copy link
Member Author

Choose a reason for hiding this comment

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

The relevant lines are now around here:

$tag_name = $this->current_element->token->node_name;

$fragment_processor->context_node = clone $this->current_element->token;
$fragment_processor->context_node->bookmark_name = 'context-node';
$fragment_processor->context_node->on_destroy = null;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants