#61351 closed enhancement (fixed)
Simplify the block bindings HTML replacement logic
Reported by: | santosguillamot | Owned by: | audrasjb |
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | 6.5 |
Component: | Editor | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Gutenberg PRs:
- https://github.com/WordPress/gutenberg/pull/61236
- https://github.com/WordPress/gutenberg/pull/61660
Proposal to change the block bindings HTML replacement logic to use a hardcoded list of selectors based on the block and a regex to substitute the inner content.
The existing logic is too complex because the HTML API doesn't support CSS selectors yet and it doesn't have an official way to modify the inner HTML. This makes it difficult to understand, iterate on it and add new functionalities.
As it will be solved in the future once the HTML API is ready, I believe it is better to keep a simple hardcoded version that is easier to understand and iterate on.
Attachments (3)
Change History (10)
This ticket was mentioned in PR #6712 on WordPress/wordpress-develop by @santosguillamot.
6 months ago
#1
- Keywords has-patch added
#2
@
6 months ago
- Component changed from General to Editor
- Keywords commit added
- Milestone changed from Awaiting Review to 6.6
- Version set to 6.5
#3
@
6 months ago
Test Report
This report validates that the indicated patch addresses the issue.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/6712
Environment
- OS: macOS 13.6
- Web Server: nginx/1.25.3
- PHP: 8.2.18
- WordPress: 6.6-alpha-57778-src
- Browser: Firefox 127.0b8
- Theme: Twenty Twenty-Four
- Active Plugins: None
Actual Results
- ✅ Paragraph content was successfully replace by the binding in the editor and on the frontend.
- ✅ Heading content was successfully replace by the binding in the editor and on the frontend.
- ✅ Button content was successfully replace by the binding in the editor and on the frontend.
Additional Notes
HTML content use to test the patch :
`
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"text_custom_field"}}}}} -->
<p>Original content</p>
<!-- /wp:paragraph -->
<!-- wp:heading {"metadata":{"bindings":{"content":{"source":"core/post-meta","args":{"key":"text_custom_field"}}}}} -->
<h2 class="wp-block-heading">Original content</h2>
<!-- /wp:heading -->
<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"metadata":{"bindings":{"text":{"source":"core/post-meta","args":{"key":"text_custom_field"}}}}} -->
<div class="wp-block-button"><a class="wp-block-buttonlink wp-element-button" href="https://wordpress.org/">Original content</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->
`
Supplemental Artifacts
See attachments
#4
@
6 months ago
- Owner set to audrasjb
- Status changed from new to accepted
Alright, looks like we're good to go with the proposed patch. Self assigning for commit
.
@audrasjb commented on PR #6712:
6 months ago
#6
committed in https://core.trac.wordpress.org/changeset/58298
Trac ticket: 61351
Backport of the following PRs: #61236 and #61660
## What?
Change the block bindings HTML replacement logic to use a hardcoded list of selectors based on the block and a regex to substitute the inner content.
Apart from that, it removes some extra breaks that are not needed.
## Why?
The existing logic is too complex because the HTML API doesn't support CSS selectors yet and it doesn't have an official way to modify the inner HTML. This makes it difficult to understand, iterate on it and add new functionalities.
As it will be solved in the future once the HTML API is ready, I believe it is better to keep a simple hardcoded version that is easier to understand and iterate on.
## How?
## Testing Instructions