Skip to content
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

HTML API: Backport updates from Core #57022

Merged
merged 1 commit into from Jan 17, 2024

Conversation

dmsnell
Copy link
Contributor

@dmsnell dmsnell commented Dec 13, 2023

Copy link

github-actions bot commented Dec 13, 2023

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/compat/wordpress-6.5/html-api/class-gutenberg-html-open-elements-6-5.php
❔ lib/compat/wordpress-6.5/html-api/class-gutenberg-html-processor-6-5.php
❔ lib/compat/wordpress-6.5/html-api/class-gutenberg-html-processor-state-6-5.php
❔ lib/compat/wordpress-6.5/html-api/class-gutenberg-html-tag-processor-6-5.php
❔ lib/load.php

@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from 58a6b69 to 43b9a9c Compare December 13, 2023 15:10
Copy link

github-actions bot commented Dec 13, 2023

Flaky tests detected in f02244a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7280154863
📝 Reported issues:

@dmsnell dmsnell marked this pull request as ready for review December 14, 2023 18:23
@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from 2f72fa6 to 2c8de78 Compare December 14, 2023 18:26
dmsnell added a commit that referenced this pull request Dec 14, 2023
@dmsnell
Copy link
Contributor Author

dmsnell commented Dec 19, 2023

@SergeyBiryukov when the WPCS ignore statements were removed in https://core.trac.wordpress.org/changeset/56753 it started preventing updates in this repo to the file where it was removed. I couldn't find a Trac ticket or any code review for that change before it was merged.

@hellofromtonya @anton-vlasenko I don't like merging over failing CI steps so I would appreciate your guidance. the WPCS rules which are preventing this PR from maintaining code harmony between the projects are the same rules that forced the change that created the obstacle; this seems silly.

@anton-vlasenko
Copy link
Contributor

anton-vlasenko commented Dec 19, 2023

I don't like merging over failing CI steps so I would appreciate your guidance. the WPCS rules which are preventing this PR from maintaining code harmony between the projects are the same rules that forced the change that created the obstacle; this seems silly.

I'm sorry to hear that misalignment in coding standards is still causing issues, @dmsnell. Hopefully, one day, coding standards can be fully aligned.

In my opinion , VariableAnalysis.CodeAnalysis.VariableAnalysis should be removed from Gutenberg since it is not enabled in Core. However, it is essential to analyze why it was added in the first place. Until this analysis takes place, I'd suggest adding the <exclude-pattern /> statement for that folder:
I.e. replacing

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
    <properties>
        <property name="allowUnusedParametersBeforeUsed" value="true"/>
    </properties>
</rule>

with

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
    <properties>
        <property name="allowUnusedParametersBeforeUsed" value="true"/>
    </properties>
    <!-- Exclude the html-api folder to prevent linter errors until coding standards are aligned. -->
    <exclude-pattern>./lib/compat/wordpress-*/html-api/*.php</exclude-pattern>
</rule>

What is your opinion on this?

@dmsnell
Copy link
Contributor Author

dmsnell commented Dec 20, 2023

What is your opinion on this?

Sounds great @anton-vlasenko - I appreciate making the adjustment to the rules, and avoiding the need to add more IGNORE statements. I'll add that change in this backport PR. For some reason I often forget that I can modify the WPCS rules in one of these backport PRs.

Thanks as always for your help.

Hopefully, one day, coding standards can be fully aligned.

We'll get there. Things have been getting better. I think in this case the problem happened because someone changed Core in a way that broke Gutenberg but that change was never run through any review process or preview in Gutenberg, so the error didn't appear until it was too late.

@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from 2c8de78 to f54fc66 Compare December 20, 2023 00:22
dmsnell added a commit that referenced this pull request Dec 20, 2023
@dmsnell dmsnell added Backport from WordPress Core Pull request that needs to be backported to the a Gutenberg release from WordPress Core [Feature] HTML API An API for updating HTML attributes in markup labels Dec 20, 2023
@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from f54fc66 to d3319f5 Compare December 20, 2023 17:21
Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

My personal preference aside, I'm afraid we can't merge this as-is: The problem is that the Dynamic Block PHP code (i.e. everything in packages/block-library/src/**/*.php) will be carried over into Core via npm package sync. But in Core, none of the back-compat Gutenberg_HTML_Tag_Processor_6_x classes exist, so it would fatal there 😕

(The same might apply to lib/block-supports/*.php, but I'm not sure about that.)

@dmsnell
Copy link
Contributor Author

dmsnell commented Dec 20, 2023

carried over into Core via npm package sync. But in Core, none of the back-compat Gutenberg_HTML_Tag_Processor_6_x classes exist, so it would fatal there 😕

is there not a way we can replace those classes during the packaging? and doesn't this same problem exist in other shared code?

I can pull these out if we need to; still trying to find a more reliable method to avoid breakages.

@ockham
Copy link
Contributor

ockham commented Dec 21, 2023

carried over into Core via npm package sync. But in Core, none of the back-compat Gutenberg_HTML_Tag_Processor_6_x classes exist, so it would fatal there 😕

is there not a way we can replace those classes during the packaging?

We have sort of the reverse mechanism in place for some function names in Dynamic Blocks' PHP (that are changed from wp_ to gutenberg_) at build time:

/**
* We need to automatically rename some functions when they are called inside block files,
* but have been declared elsewhere. This way we can call Gutenberg override functions, but
* the block will still call the core function when updates are back ported.
*/
const prefixFunctions = [
'wp_apply_colors_support',
'wp_enqueue_block_support_styles',
'wp_get_typography_font_size_value',
'wp_style_engine_get_styles',
'wp_get_global_settings',
];

To avoid confusion, we'd need to align with that and also transform from WP_ to Gutenberg_ (rather than the other way round).

and doesn't this same problem exist in other shared code?

I think we have a recommendation somewhere that Dynamic Blocks generally use functions rather than classes (and class methods); although upon some further research, there seems to be some precedent in the guise of some Style Engine related class names which are indeed transformed:

replaceClasses: [
'WP_Style_Engine_CSS_Declarations',
'WP_Style_Engine_CSS_Rules_Store',
'WP_Style_Engine_CSS_Rule',
'WP_Style_Engine_Processor',
'WP_Style_Engine',
],

...although the transformed names seem to look a bit different than the "usual" Gutenberg_*_x_y scheme:

const classSuffix = '_Gutenberg';
const functionPrefix = 'gutenberg_';
content = content.toString();
// Replace class names.
content = content.replace(
new RegExp( replaceClasses.join( '|' ), 'g' ),
( match ) => `${ match }${ classSuffix }`
);

I can pull these out if we need to; still trying to find a more reliable method to avoid breakages.

Thank you. How about we land the backport of WordPress/wordpress-develop#5535 and WordPress/wordpress-develop#5725 separately first (to unblock further work), and file a separate PR for the other changes (since they might need some more tweaking)?


TBH I'm still not 100% convinced we should really duplicate all classes from Core in GB's back-compat layer and update all code to use the latter, given that it'll add a ton more code that will need syncing and require that extra magic at build time, which will likely mean another list of classes tucked away in a webpack config that we'll need to keep updated.

@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from f02244a to 444a0c5 Compare December 23, 2023 02:02
@dmsnell
Copy link
Contributor Author

dmsnell commented Dec 23, 2023

@ockham this has been pared back to only include the changes to the existing classes.

@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from f3fb05e to e5b2e6a Compare December 23, 2023 02:19
dmsnell added a commit that referenced this pull request Dec 23, 2023
Updates from WordPress/wordpress-develop at 54a09a7ec99c59b8e640bd5aacebfdbf03bb02cc

 - WordPress/wordpress-develop#5535
   Adds support for H1 - H6 elements in the HTML Processor.

 - WordPress/wordpress-develop#5725
   Pause the Tag Processor when reaching the end of the document
   inside an incomplete syntax element.

 - Incorporates linting changes from "TODO:" to "todo"

This patch adds the blanket exclusion from the HTML API compatability
layer after they were removed and started blocking updates from Core.

The PHP files in the compatability layer are merged and maintained in
the Core repo and all changes or updates need to happen first in Core
and then be brought over to Gutenberg as built files. From Gutenberg's
perspective they are no different than NPM packages.

Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from e5b2e6a to ca8d29d Compare January 1, 2024 01:03
dmsnell added a commit that referenced this pull request Jan 1, 2024
Updates from WordPress/wordpress-develop at 54a09a7ec99c59b8e640bd5aacebfdbf03bb02cc

 - WordPress/wordpress-develop#5535
   Adds support for H1 - H6 elements in the HTML Processor.

 - WordPress/wordpress-develop#5725
   Pause the Tag Processor when reaching the end of the document
   inside an incomplete syntax element.

 - Incorporates linting changes from "TODO:" to "todo"

This patch adds the blanket exclusion from the HTML API compatability
layer after they were removed and started blocking updates from Core.

The PHP files in the compatability layer are merged and maintained in
the Core repo and all changes or updates need to happen first in Core
and then be brought over to Gutenberg as built files. From Gutenberg's
perspective they are no different than NPM packages.

Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from ca8d29d to 7b6607f Compare January 12, 2024 16:28
@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from 7b6607f to bed2804 Compare January 12, 2024 16:34
@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from bed2804 to b6586a4 Compare January 12, 2024 16:38
Updates from WordPress/wordpress-develop at 54a09a7ec99c59b8e640bd5aacebfdbf03bb02cc

 - WordPress/wordpress-develop#5535
   Adds support for H1 - H6 elements in the HTML Processor.

 - WordPress/wordpress-develop#5725
   Pause the Tag Processor when reaching the end of the document
   inside an incomplete syntax element.

 - Incorporates linting changes from "TODO:" to "todo".

 - WordPress/wordpress-develop#5762
   Handles the "all other tags" rules in IN BODY insertion mode.

 - WordPress/wordpress-develop#5539
   Adds support for list elements in the HTML Processor.

This patch adds the blanket exclusion from the HTML API compatability
layer after they were removed and started blocking updates from Core.

The PHP files in the compatability layer are merged and maintained in
the Core repo and all changes or updates need to happen first in Core
and then be brought over to Gutenberg as built files. From Gutenberg's
perspective they are no different than NPM packages.

Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com>
Co-authored-by: Bernie Reiter <96308+ockham@users.noreply.github.com>
@dmsnell dmsnell force-pushed the html-api/backport-updates-from-core branch from b6586a4 to d8d7bbc Compare January 13, 2024 13:16
Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

LGTM!

I've compared all files to their counterparts in the https://github.com/WordPress/wordpress-develop repo. They are all exact matches, except for the different class names (as expected).

@dmsnell dmsnell merged commit 4e982f4 into trunk Jan 17, 2024
55 checks passed
@dmsnell dmsnell deleted the html-api/backport-updates-from-core branch January 17, 2024 16:31
@github-actions github-actions bot added this to the Gutenberg 17.6 milestone Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport from WordPress Core Pull request that needs to be backported to the a Gutenberg release from WordPress Core [Feature] HTML API An API for updating HTML attributes in markup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants