Skip to content

Blocks: Keep HTML attributes a block doesn't know - #85716

Open
ellatrix wants to merge 11 commits into
trunkfrom
try/unknown-html-attributes
Open

ellatrix wants to merge 11 commits into
trunkfrom
try/unknown-html-attributes

Conversation

@ellatrix

@ellatrix ellatrix commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What?

See #10204 and #46002.

A block whose HTML element has attributes the block doesn't know, like data-note, role or an inline background, now opens as a valid block instead of an invalid one. The attributes are shown in the editor and saved again when the block is edited.

This is a prep PR for #85524, which reads HTML without block delimiters as blocks: any paragraph should open as a paragraph, whatever attributes it has.

Why?

Today one extra attribute is enough to make a block invalid ("This block contains unexpected or invalid content"). A paragraph is worse: its oldest deprecation takes any invalid paragraph and nests it in another <p>, so saving writes <p><p data-note="tip">…</p></p>.

How?

  • Parser: if a block is still invalid after its deprecations ran, the attributes of its root element that its save doesn't produce are kept in a new htmlAttributes attribute, and the block is validated again. For style, only the properties save doesn't set are kept. Classes are left to the existing custom class name fix. Running after deprecations means old blocks still migrate as before: no fixture changes.
  • Convert to blocks: rawHandler does the same for each block it converts, so a classic <p data-note="tip"> keeps data-note when converted. Attributes are only kept if the block then matches the original element, so an <img> that becomes an Image block doesn't pass its attributes to the <figure>.
  • htmlAttributes is added to every block, with role: 'local', so it never goes in the delimiter; it's always read from the HTML. This is the same idea as RichText's unregisteredAttributes, from the Format API (Format API #10209): attributes a format doesn't know are kept and written back, and the format's own win.
  • Save: a blocks.getSaveContent.extraProps hook adds them back, after the block's own props, which win.
  • Allowed attributes: only global attributes that describe content are saved and shown: data-*, aria-*, role, id, title, lang, dir, translate, style and microdata (item*). The list comes from the HTML spec, so it holds in an editor without WordPress too. Anything else, like event handlers or links, isn't saved, so that block stays invalid as on trunk and keeps its original HTML.
  • Editor: a block list hook shows them on the block.
  • Paragraph: the oldest deprecation, for paragraphs saved without their <p>, no longer takes content that has a <p>, using the same p selector the paragraph reads its text with.

Testing Instructions

  1. Open this Playground. It opens a post with a heading that has a data-note attribute, and a paragraph that also has an inline background and border.
  2. Neither block shows an invalid block warning. On trunk, the heading shows "Block contains unexpected or invalid content", and the paragraph is saved inside another <p> without a warning.
  3. Type at the end of the paragraph, then open the Code editor (Options → Code editor).
  4. Both blocks keep their attributes. The paragraph is saved once, with style="color:#000000;background-color:#fffbe6;border-left:4px solid #f0b849;padding:12px" data-note="tip", not nested in another <p>.

The new e2e test, "Invalid blocks › should keep attributes a block does not know", fails on trunk: the paragraph's content becomes the whole nested <p>.

"Invalid blocks › should not keep event handlers a block does not know" fails without the allow list: the paragraph with onclick opens as valid.

"Classic › should keep attributes a block does not know when converted to blocks" fails without the change: the converted paragraph loses data-note and its background.

Testing Instructions for Keyboard

  1. Open the post, press Tab until the yellow paragraph is focused, press End and type.
  2. Press Ctrl+Shift+Alt+M (Cmd+Shift+Option+M on a Mac) for the Code editor and check the markup as above.

Screenshots or screencast

Before After
Before: the heading shows the invalid block warning After: the heading and the paragraph open without warnings
Before: the paragraph is saved inside another paragraph After: the paragraph is saved once, with its attributes

Before, the heading is invalid, and the paragraph looks fine in the editor but is saved inside another <p>.

Use of AI Tools

Written with Claude Code (Claude Opus 5.5).

🤖 Generated with Claude Code

A block whose root element has attributes its `save` doesn't produce, like
`data-note` or an inline background, is now valid. Those attributes are kept
in `htmlAttributes`, shown in the editor, and saved again. They're read only
after the block's deprecations had the chance to read the HTML, so old
blocks still migrate as before.

The paragraph's oldest deprecation, for paragraphs saved without their
`<p>`, no longer takes a paragraph with one and nests it in another.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @tomusborne.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: tomusborne.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: dmsnell <dmsnell@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +424 B (0%)

Total Size: 8.56 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 542 kB +211 B (+0.04%)
build/scripts/block-library/index.min.js 401 kB +28 B (+0.01%)
build/scripts/blocks/index.min.js 45.1 kB +185 B (+0.41%)

674a41b Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 7446cfa trunk % Change
timeToFirstByte 57.55 ms +10.69% -4.87% 57 ms +12.98% -3.68% 0.96%
largestContentfulPaint 96 ms +10.42% -8.33% 96 ms +12.5% -4.17% 0%
lcpMinusTtfb 37.2 ms +15.99% -6.18% 38.3 ms +15.93% -8.62% -2.87%
wpBeforeTemplate 30.58 ms +16.42% -5.4% 30.27 ms +11.6% -1.19% 1.02%
wpTemplate 22 ms +4.95% -2.45% 22.49 ms +10.58% -4.49% -2.18%
wpTotal 53.59 ms +9.11% -5.06% 53.33 ms +13.35% -3.64% 0.49%
wpMemoryUsage 7.70 MB +0% -0% 7.67 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 7446cfa trunk % Change
timeToFirstByte 47.6 ms +12.08% -1.37% 48.55 ms +5.46% -3.5% -1.96%
largestContentfulPaint 104 ms +3.85% -1.92% 104 ms +3.85% -1.92% 0%
lcpMinusTtfb 56.5 ms +0.97% -3.63% 55.45 ms +1.89% -2.43% 1.89%
wpBeforeTemplate 27.49 ms +16.77% -1.42% 27.67 ms +7.95% -2.35% -0.65%
wpTemplate 17.22 ms +3.37% -5.11% 17.12 ms +4.79% -3.39% 0.58%
wpTotal 44.53 ms +12.24% -1.66% 45.51 ms +4.61% -4.2% -2.15%
wpMemoryUsage 6.39 MB +0% -0% 6.36 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 7446cfa trunk % Change
mediaProcessingJpeg 401.43 ms +1.38% -0.15% 400.6 ms +0.43% -0.76% 0.21%
mediaProcessingAvif 6142.44 ms +0.05% -0.19% 6105.43 ms +0.09% -0.19% 0.61%
mediaProcessingJpegToAvif 4234.32 ms +0.37% -0.27% 4197.95 ms +0.35% -0.02% 0.87%

media-upload

Metric 7446cfa trunk % Change
jpegUploadProcessing 1464.49 ms +2.73% -1.65% 1429.33 ms +0.3% -0.69% 2.46%
pngUploadProcessing 224.07 ms +16.68% -14% 206.55 ms +18.62% -13.71% 8.48%
largeJpegUploadProcessing 1426.75 ms +1% -0.7% 1419.98 ms +0.89% -0.7% 0.48%
multipleImageUploadProcessing 1535.26 ms +0.86% -1.63% 1522.36 ms +1.24% -0.81% 0.85%

post-editor

Metric 7446cfa trunk % Change
serverResponse 479.34 ms +5.97% -4.42% 529.91 ms +1.33% -7.14% -9.54%
firstPaint 262.44 ms +91.48% -11% 288.09 ms +29.97% -23.69% -8.9%
domContentLoaded 868.71 ms +0.78% -0.5% 870.44 ms +0.87% -1.39% -0.2%
loaded 869.9 ms +0.79% -0.51% 871.52 ms +0.88% -1.38% -0.19%
firstContentfulPaint 511.64 ms +1.49% -1.78% 519.26 ms +1.81% -4.71% -1.47%
firstBlock 3028.89 ms +1.19% -3.31% 2998.9 ms +0.69% -1.53% 1%
type 17.09 ms +7.08% -5.97% 17.53 ms +4.39% -5.19% -2.51%
typeWithoutInspector 16.66 ms +2.64% -3.84% 16.96 ms +6.49% -2.89% -1.77%
typeWithTopToolbar 20.73 ms +8.54% -4.87% 22.44 ms +7.09% -7.58% -7.62%
typeContainer 8.2 ms +7.44% -6.83% 8.27 ms +11.85% -5.44% -0.85%
focus 122.96 ms +3.05% -7.16% 109.79 ms +12.15% -5.51% 12%
firstFocus 220.24 ms +0% -0% 236.52 ms +0% -0% -6.88%
selectAll 460.41 ms +1.18% -2.57% 469.69 ms +0.19% -3.81% -1.98%
undo 31.25 ms +5.41% -6.69% 29.7 ms +9.16% -4.88% 5.22%
listViewOpen 76.27 ms +7.66% -10.71% 74.25 ms +8.9% -3.33% 2.72%
inserterOpen 41.71 ms +5.06% -10.84% 43.31 ms +1.25% -6.47% -3.69%
inserterHover 10.64 ms +12.59% -6.48% 11.44 ms +4.55% -16.61% -6.99%
inserterSearch 8.32 ms +3.85% -10.22% 8.03 ms +8.34% -4.86% 3.61%
loadPatterns 611.84 ms +5.52% -3.66% 637.67 ms +1.58% -8.28% -4.05%
wpTotal 470.07 ms +6.13% -4.6% 518.67 ms +1.64% -6.89% -9.37%
wpMemoryUsage 14.75 MB +0% -0% 14.72 MB +0% -0% 0.24%
wpDbQueries 55 +0% -1.82% 55 +0% -1.82% 0%

site-editor

Metric 7446cfa trunk % Change
serverResponse 500.3 ms +6.16% -2.95% 522.15 ms +2.33% -9.34% -4.18%
firstPaint 265.74 ms +24.08% -7.55% 277.52 ms +17.69% -7.89% -4.24%
domContentLoaded 905.88 ms +0.48% -2.16% 909.82 ms +4.18% -1.25% -0.43%
loaded 906.81 ms +0.48% -2.11% 911.01 ms +4.16% -1.25% -0.46%
firstContentfulPaint 490.67 ms +5.64% -2.26% 504.89 ms +4.24% -0.53% -2.82%
firstBlock 3946.68 ms +1.43% -1.84% 4050.29 ms +1.01% -0.38% -2.56%
type 17.66 ms +5.78% -4.13% 19.35 ms +3.05% -7.96% -8.73%
navigate 116.9 ms +11.72% -5.67% 132.83 ms +4.67% -3.02% -11.99%
loadPatterns 1130.45 ms +5.65% -13.54% 1325.36 ms +3.45% -7.44% -14.71%
loadPages 949.11 ms +5.15% -1.77% 990.1 ms +3.08% -1.79% -4.14%
wpTotal 490.9 ms +6.21% -2.88% 512.45 ms +2.38% -9.4% -4.21%
wpMemoryUsage 12.77 MB +0% -0% 12.74 MB +0% -0% 0.24%
wpDbQueries 44 +2.27% -0% 44 +2.27% -0% 0%

674a41b Run

🏁 Flaky tests

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.

Navigates the items list via UP/DOWN arrow keys (Site Editor v2) in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page One')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByLabel('Page One') with timeout 5000ms
  - waiting for getByLabel('Page One')
    14 × locator resolved to <button type="button" aria-pressed="true" data-active-item="true" id="view-list-0-12-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-12-label" aria-describedby="view-list-0-12-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:149:49
Navigates the list via UP/DOWN arrow keys from action buttons (Site Editor v2) in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByRole('row', { name: 'Page One View Actions' }).getByRole('button', { name: 'View' })
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByRole('row', { name: 'Page One View Actions' }).getByRole('button', { name: 'View' }) with timeout 5000ms
  - waiting for getByRole('row', { name: 'Page One View Actions' }).getByRole('button', { name: 'View' })
    14 × locator resolved to <button type="button" tabindex="-1" class="components-button is-small" id="view-list-0-14-primary-action-view-post">View</button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:252:5
can be converted to a quote in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

@@ -1,9 +1,9 @@
  <!-- wp:quote -->
  <blockquote class="wp-block-quote"><!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>one</li>
+ <li>ne</li>
  <!-- /wp:list-item -->

  <!-- wp:list-item -->
  <li>two</li>
  <!-- /wp:list-item --></ul>

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:436:52
moves selected text into another paragraph in /test/e2e/specs/editor/various/draggable-blocks.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Array [
    Object {
      "attributes": Object {
-       "content": "First third",
+       "content": "First second third",
      },
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {
-       "content": "Fourth second fifth",
+       "content": "Fourth fifth",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:1167:41
moves selected text within a paragraph in /test/e2e/specs/editor/various/draggable-blocks.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "content": "second First third",
+       "content": "First second third",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:1209:41
should cut and paste individual blocks with collapsed selection in /test/e2e/specs/editor/various/copy-cut-paste.spec.js, passed after 1 failed attempt.
Error: expect(string).toMatchSnapshot(expected) failed

  @@ -1,3 +1,3 @@
   <!-- wp:paragraph -->
  -<p>2Cut - collapsed selection</p>
  +<p>2</p>
   <!-- /wp:paragraph -->


    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/copy-cut-paste.spec.js:45:49
should insert a line break on shift+enter in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>a<br></li>
+ <li><br></li>
  <!-- /wp:list-item --></ul>
  <!-- /wp:list -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:1210:52
should keep the list type when indenting an ordered list item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

@@ -1,8 +1,8 @@
  <!-- wp:list {"ordered":true} -->
  <ol class="wp-block-list"><!-- wp:list-item -->
- <li>one<!-- wp:list {"ordered":true} -->
+ <li>ne<!-- wp:list {"ordered":true} -->
  <ol class="wp-block-list"><!-- wp:list-item -->
  <li>two</li>
  <!-- /wp:list-item --></ol>
  <!-- /wp:list --></li>
  <!-- /wp:list-item --></ol>

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:916:52
should leave nested list intact when deleting the parent item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  1
+ Received  + 19

@@ -1,19 +1,36 @@
  Array [
    Object {
+     "attributes": Object {
+       "content": "1",
+       "dropCap": false,
+     },
+     "innerBlocks": Array [],
+     "name": "core/paragraph",
+   },
+   Object {
+     "attributes": Object {
+       "ordered": false,
+       "values": "",
+     },
      "innerBlocks": Array [
        Object {
          "attributes": Object {
-           "content": "1",
+           "content": "",
          },
          "innerBlocks": Array [
            Object {
+             "attributes": Object {
+               "ordered": false,
+               "values": "",
+             },
              "innerBlocks": Array [
                Object {
                  "attributes": Object {
                    "content": "a",
                  },
+                 "innerBlocks": Array [],
                  "name": "core/list-item",
                },
              ],
              "name": "core/list",
            },
@@ -22,10 +39,11 @@
        },
        Object {
          "attributes": Object {
            "content": "3",
          },
+         "innerBlocks": Array [],
          "name": "core/list-item",
        },
      ],
      "name": "core/list",
    },
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:3017:38
should merge a following sibling list into the outermost list with Delete from a nested item (#77245) in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

@@ -8,11 +8,11 @@
          "innerBlocks": Array [
            Object {
              "innerBlocks": Array [
                Object {
                  "attributes": Object {
-                   "content": "b‸",
+                   "content": "b",
                  },
                  "name": "core/list-item",
                },
              ],
              "name": "core/list",
@@ -25,11 +25,11 @@
    },
    Object {
      "innerBlocks": Array [
        Object {
          "attributes": Object {
-           "content": "1",
+           "content": "‸1",
          },
          "innerBlocks": Array [
            Object {
              "innerBlocks": Array [
                Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:2854:41
should outdent list items when deleting an empty parent at the top in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 19
+ Received  +  1

- Array [
-   Object {
-     "innerBlocks": Array [
-       Object {
-         "attributes": Object {
-           "content": "a",
-         },
-         "name": "core/list-item",
-       },
-       Object {
-         "attributes": Object {
-           "content": "b",
-         },
-         "name": "core/list-item",
-       },
-     ],
-     "name": "core/list",
-   },
- ]
+ Array []

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:3074:41
should partially select with shift + click in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  1
+ Received  + 11

  Array [
    Object {
      "attributes": Object {
-       "content": "<strong>1</strong>|2",
+       "content": "<strong>1</strong>[",
+       "dropCap": false,
+     },
+     "innerBlocks": Array [],
+     "name": "core/paragraph",
+   },
+   Object {
+     "attributes": Object {
+       "content": "]2",
+       "dropCap": false,
      },
+     "innerBlocks": Array [],
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:1599:41
should select by dragging into nested block in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
TimeoutError: locator.hover: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('[name="editor-canvas"]').contentFrame().getByRole('document', { name: 'Block: Paragraph' }).first()
    - locator resolved to <p role="document" data-empty="false" aria-multiline="true" aria-readonly="false" data-title="Paragraph" contenteditable="true" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-2e6e3c3d-5a90-4c79-9eee-5d4cec801209" data-block="2e6e3c3d-5a90-4c79-9eee-5d4cec801209" class="block-editor-rich-text__editable block-editor-block-list__block wp-block wp-block-paragraph rich-text">1</p>
  - attempting hover action
    2 × waiting for element to be visible and stable
      - element is visible and stable
      - scrolling into view if needed
      - done scrolling
      - <button id="_r_4b_" type="button" tabindex="-1" aria-label="Italic" aria-pressed="false" data-toolbar-item="true" class="components-button components-toolbar-button is-compact has-icon">…</button> from <div tabindex="-1" data-wp-c16t="true" data-wp-component="Popover" class="components-popover block-editor-block-popover block-editor-block-list__block-popover is-positioned is-unstyled">…</div> subtree intercepts pointer events
    - retrying hover action
    - waiting 20ms
    2 × waiting for element to be visible and stable
      - element is visible and stable
      - scrolling into view if needed
      - done scrolling
      - <button id="_r_4b_" type="button" tabindex="-1" aria-label="Italic" aria-pressed="false" data-toolbar-item="true" class="components-button components-toolbar-button is-compact has-icon">…</button> from <div tabindex="-1" data-wp-c16t="true" data-wp-component="Popover" class="components-popover block-editor-block-popover block-editor-block-list__block-popover is-positioned is-unstyled">…</div> subtree intercepts pointer events
    - retrying hover action
      - waiting 100ms
    17 × waiting for element to be visible and stable
       - element is visible and stable
       - scrolling into view if needed
       - done scrolling
       - <button id="_r_4b_" type="button" tabindex="-1" aria-label="Italic" aria-pressed="false" data-toolbar-item="true" class="components-button components-toolbar-button is-compact has-icon">…</button> from <div tabindex="-1" data-wp-c16t="true" data-wp-component="Popover" class="components-popover block-editor-block-popover block-editor-block-list__block-popover is-positioned is-unstyled">…</div> subtree intercepts pointer events
     - retrying hover action
       - waiting 500ms

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:561:20
should update the URL from the last navigation if only varies in the URL fragment in /test/e2e/specs/interactivity/router-navigate.spec.ts, passed after 1 failed attempt.
Error: expect(locator).toHaveText(expected) failed

Truncated. See the full report.

674a41b Run

@github-actions github-actions Bot added [Package] Blocks /packages/blocks [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor labels Oct 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mamaduka

Copy link
Copy Markdown
Member

Interesting. Kind of reminds me of additionalProperties from a REST API. There's a similar problem with formats: #27345, which could use a similar system.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ellatrix

Copy link
Copy Markdown
Member Author

It's the same we do in RichText (unregistered attributes)

ellatrix and others added 2 commits October 27, 2026 10:49
Read the root element with the parser's parseHtml, convert style keys
with getReactStyleKey, inline the merge, and check for a top-level <p>
in the paragraph deprecation with a tag source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ributes

# Conflicts:
#	packages/blocks/CHANGELOG.md
@ellatrix
ellatrix marked this pull request as ready for review October 27, 2026 18:07
@ellatrix ellatrix added the [Type] Enhancement A suggestion for improvement. label Oct 27, 2026
ellatrix and others added 3 commits October 27, 2026 11:11
Add an e2e test for content with a <p> inside another element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rawHandler now keeps the attributes of an element that the block's save
doesn't produce, as the parser does, when the block then matches its HTML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
for ( const [ name, value ] of getHTMLRootElementAttributes( innerHTML ) ) {
if ( name === 'style' ) {
const style = value
.split( ';' )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we have a CSS parser in the browser. it’s not exactly easy (@sirreal has dealt with this too), but we should not be introducing the kind of basic parsing defects that splitting on a semicolon does. that is, instead of ad-hoc parsers that handle some familiar CSS, we should try hard to reach for method which reliably tokenize or parse out the information and then we can reassemble it reliably and structurally

( [ name, value ] ) =>
! name.startsWith( 'on' ) &&
name !== 'contenteditable' &&
! /^\s*javascript:/i.test( value )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as with the work @adamsilverstein is doing with Core-29807, we could build this out more robustly and block javascript: schemes in srcset, and src, and href.

do we know here whether the user has unfiltered_html? otherwise we are preventing admin-level users from storing JavaScript handlers, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could also look at the utilities in https://github.com/WordPress/gutenberg/blob/trunk/packages/interactivity/src/directives/utils/url.ts that was just introduced in db69faf. There's an improved javascript: test and a set of urlAttributes

ellatrix and others added 3 commits October 27, 2026 19:01
Save and show only global attributes from the HTML spec that don't change how
the content behaves: data-*, aria-*, role, id, title, lang, dir, translate,
style and microdata. Anything else, like event handlers, isn't saved, so the
block stays invalid and keeps its original HTML. This holds without KSES, in
an editor outside WordPress, and replaces the editor-only filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Splitting a style attribute on ";" breaks values like url("data:…;…"), and
doing it properly needs a CSS parser. A block with an inline style its save
doesn't write stays invalid, as on trunk, and keeps its original HTML. Styles
can follow in their own PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ributes

# Conflicts:
#	packages/block-library/CHANGELOG.md
Comment on lines +32 to +36
for ( const declaration of style.split( ';' ) ) {
const colonAt = declaration.indexOf( ':' );
const property = declaration.slice( 0, colonAt ).trim();
if ( colonAt === -1 || ! property ) {
continue;

@sirreal sirreal Oct 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Like @dmsnell mentioned in #85716 (comment), this will get tripped up on valid inputs, ; and : can appear in places other than property: value;. They can appear in at least strings and idents.

I don't have a great recommendation for how to do this in a browser, other than using a CSS parsing library or implementing one. This comment is relevant, but in short, when a browser parses CSS, we get a browser's CSSOM view of the CSS.

That means things like:

  • loss of duplicated properties
  • discarding properties or values a browser doesn't support
  • possible expansion of shorthand properties

Specifically when trying to get a style property into a React-like object form, there may also be problems with value types. CSS source text is made up of strings, so a JavaScript string of CSS text is a string like '"css string value"' or a number as '10'. I'm not sure exactly how React handles those things, whether you might get extra " in the string example.

Here's a gnarly example:

<ul style="
  outline: 1px solid black;
  border-top-right-radius: 20px;
  corner-shape: scoop !important;
  color: blue;
  color: red;
  list&#x2d;style-type:';';
  &#x2d;&#x2d;custom-prop: ident-semi-\;-colon\:-lol;
  line-height:10;
  font-size:16px;
"><li>item</ul>

And a promising (but problematic!) approach:

Object.fromEntries(
    [...$0.style].map( prop => {
        const res = [prop, $0.style.getPropertyValue(prop)];
        if ( $0.style.getPropertyPriority(prop) ) {
            res[1] += ' !important'
        }
        return res;
    })
)

In Chrome returns (note expansion of outline and corner-shape, overridden blue color is absent):

{
    "outline-color": "black",
    "outline-style": "solid",
    "outline-width": "1px",
    "border-top-right-radius": "20px",
    "color": "red",
    "list-style-type": "\";\"",
    "--custom-prop": "ident-semi-\\;-colon\\:-lol",
    "line-height": "10",
    "font-size": "16px",
    "corner-top-left-shape": "scoop",
    "corner-top-right-shape": "scoop",
    "corner-bottom-right-shape": "scoop",
    "corner-bottom-left-shape": "scoop"
}

While Firefox returns (unsupported corner-shape is dropped):

{
  "outline-color": "black",
  "outline-style": "solid",
  "outline-width": "1px",
  "border-top-right-radius": "20px",
  "color": "red",
  "list-style-type": "\";\"",
  "--custom-prop": "ident-semi-\\;-colon\\:-lol",
  "line-height": "10",
  "font-size": "16px"
}

To make this concrete, 63568 is a ticket caused by this simplistic type of CSS parsing and it's difficult to resolve at this point because of the data already on live sites.

@tomusborne

tomusborne commented Oct 30, 2026 •

Copy link
Copy Markdown

This collides with an existing attribute name. GenerateBlocks and GenerateBlocks Pro (hundreds of thousands of sites) declare htmlAttributes as a comment-serialized attribute on 31 blocks. addAttribute overwrites that definition with role: 'local', so the first save removes it from the delimiter.

Tested on this PR’s build with GenerateBlocks 2.5.0, editing only a paragraph and saving:

  • Blocks with the attributes on their root element are recovered from the HTML on reload.
  • A Media block with a link saves as <a><img src alt></a>. Only the root <a> is read, so after reload the block is invalid and src/alt are gone from its attributes.
  • PHP that reads $attributes['htmlAttributes'] no longer gets a value. Attributes that are never written to the HTML, such as our form field controls’ placeholder and pattern, have no recovery path.

Could this use a namespaced attribute name? A guard for blocks that already declare it wouldn’t be enough, because fixHtmlAttributes and hasSupport also check that name. Any plugin using this fairly generic name could be affected.

Separately, for any block that already has this attribute and spreads it in save, the allow-list doesn’t apply: fixHtmlAttributes keeps everything, and a block with onclick reloaded as valid rather than staying invalid as the description says.

Core’s other attribute hooks, such as anchor, align and allowedBlocks, return early when a block already declares the attribute. This hook skips that check and isn’t gated by a block support, so it overwrites existing definitions on every block. Could it follow the same convention, and could its other checks ignore blocks that declare their own htmlAttributes?

This branch has not been deployed

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

Labels

[Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Package] Blocks /packages/blocks [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants