Repository navigation
Conversation
When one block changes, the editor serializes every block again from `save`, so blocks the user never touched could come out with different attribute order or style formatting. The parser now keeps the loaded HTML pieces of each block that parsed valid with no fixes or migrations, keyed by its attributes object. Any edit gives a block a new attributes object, so the serializer writes the loaded pieces only for untouched blocks, with inner blocks serialized in their slots while their number is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. 📦 Bundle sizeSize Change: +96 B (0%) Total Size: 8.56 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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. Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
Keep a shallow copy of the parsed attributes and compare against it, so code that changes a parsed block's attributes in place before serializing gets the new markup instead of the loaded one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
See #38922.
When you edit one block, every block you didn't touch now saves with exactly the HTML it was loaded with, instead of being rebuilt from its
savefunction.Example, on trunk: a post has this heading and a paragraph. You type one letter in the paragraph and save. The heading you never touched is rewritten too:
The same happens to the wrapper of a Group or Columns block when you type in a block inside it, and to any HTML written by hand, by another tool, or by an older version of a block's
savethat still validates.Why?
Once any block in a post changes, the editor serializes every block again from
save. Validation treats the two headings above as the same, so nothing breaks, but the post's HTML changes without the user doing anything: revisions show changes in blocks nobody edited, and anyone who formats their HTML by hand or with another tool loses that formatting. Loading and saving a post should give back the input, and only the blocks a user changed should serialize differently. #38922 describes the root cause: the editor rebuilds output from attributes instead of using what it loaded.How?
innerContent, with a slot for each inner block) in aWeakMap, keyed by the block's attributes object, along with a shallow copy of those attributes. It does this only when the block parsed valid with no built-in fixes and no deprecation, and isn't a Classic or unknown block.UPDATE_BLOCK_ATTRIBUTESreducer only copies when a value differs), so the serializer finds the loaded pieces only for blocks nobody changed. It also checks the attributes are shallow equal to the copy, which catches code that changes a parsed block's attributes in place (parse, setattributes.content,serialize). A change nested deeper, such asattributes.style.color, is not caught.getBlockInnerHTMLwrites those pieces, with the inner blocks serialized in their slots, as long as the block still has the same number of inner blocks. Otherwise it runssaveas before.What this means:
save.save, as before.save, as before.<!-- wp:heading {...} -->) is still rebuilt from attributes. Not in this PR.Why a
WeakMapand not the parsed attributes on the block: real-time collaboration copies every block property into its shared document (makeBlocksSerializableincore-data/src/utils/crdt-blocks.ts), and attributes hold rich text objects it can't store.Open questions:
savereads its children would keep stale markup while only a child changes. No core block'ssave.jsreadsinnerBlocks(checked by search); deprecatedsavefunctions and third-party blocks are not checked.blocks.getSaveContent.extraPropsfilter added after a post is parsed applies only to blocks edited afterwards, not to untouched ones.isValidcondition keeps invalid blocks on their current path (they already save from their raw source). No test fails without it.The
full-contentfixture test now saves copies of the parsed blocks, so the.serialized.htmlfixtures keep recording whatsavewrites. Without that, 48 fixtures would change to match their hand-formatted input. I checked every one of those changes: all are equivalent HTML (whitespace, attribute and class order,"vs",…vs…,controlsvscontrols="",/>vs/>).Testing Instructions
A Playground link will be added here once CI has built the plugin for this PR.
<h2 style="color: #ff6347;" class="wp-block-heading has-text-color">, and the Group still reads<div style="color: #ff6347;" class="wp-block-group has-text-color">. On trunk both are rewritten.save.The e2e tests in
test/e2e/specs/editor/various/untouched-blocks.spec.jscover this, and unit tests inpackages/blocks/src/api/parser/test/index.jsdom.test.jsxcoverserialize( parse( content ) )and attributes changed in place. The first two fail on trunk; the last two check that a parent is rebuilt when a child is added and that an unknown block keeps its delimiters.Testing Instructions for Keyboard
Same steps; nothing in the interface changes.
Screenshots or screencast
No visible change in the editor. The difference is in the saved HTML, shown in the table above.
Use of AI Tools
Claude Code (Claude Opus) researched prior work, wrote the code, the tests and this description, directed by @ellatrix.
🤖 Generated with Claude Code