Skip to content

fix: ignore load-time content changes in getTitleAndContent - #956

Draft
dcalhoun wants to merge 4 commits into
trunkfrom
fix/untouched-posts-report-changes
Draft

dcalhoun wants to merge 4 commits into
trunkfrom
fix/untouched-posts-report-changes

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes #943. Fixes CMM-2930.

getTitleAndContent() reported changed: true for untouched posts when core migrated a block while parsing (e.g., legacy-aligned headings and paragraphs) or a block wrote attributes on mount as non-persistent changes (e.g., VideoPress caching its embed).

It now compares markup only once the post's content edit differs from the one at open, or the host has already received edited content. Core creates that edit for persistent changes only, never for parse-time migrations or non-persistent writes, so this matches whether core considers the content edited.

Additional AI-generated details
  • Why not compare markup alone: for an untouched post, getEditedPostContent() returns the stored markup, but the baseline is serialize( parse( content ) ), so migrated blocks never match. Non-persistent writes really do change the serialized content, so no baseline can hide them.
  • Why keep the serialized baseline: after any real edit, getEditedPostContent() returns serializer output, so the serialized baseline is the like-for-like comparison. A raw baseline would report edits that cancel out on migrated blocks as a change; an E2E test covers this and fails with raw seeding.
  • Why compare with the edit at open: core keeps one content edit for a run of typing, so comparing with the edit seen at the last read hid keystrokes typed after it.
  • Known limitation: a paragraph whose legacy align attribute lacks the matching has-text-align-* class is migrated by a non-persistent write on mount. Core groups the user's first text-alignment change on that block with that write, so it creates no content edit and is reported as changed: false until the next persistent edit. Core's isEditedPostDirty() misses it too; accepted as narrow.

Testing instructions

  1. Create a post with this content:

    <!-- wp:heading {"textAlign":"center"} -->
    <h2 class="wp-block-heading has-text-align-center">Centered heading</h2>
    <!-- /wp:heading -->
    
    <!-- wp:paragraph {"align":"center"} -->
    <p class="has-text-align-center">Centered paragraph</p>
    <!-- /wp:paragraph -->
  2. Open it in the demo app without editing.

  3. In the web inspector, run window.editor.getTitleAndContent(). Expect changed: false.

  4. Type in the paragraph and run it again. Expect changed: true.

Note: run getTitleAndContent() once per step; each changed: true result advances the baseline.

🤖 Generated with Claude Code

dcalhoun and others added 2 commits November 30, 2026 13:50
Untouched posts reported changed: true when core migrated a block while
parsing or a block wrote non-persistent attributes on mount. Count a
content change only when core replaced the content edit, which it does
for every persistent change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Guards the serialized baseline: seeding it with the raw stored markup
would report these edits as a change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the [Type] Bug An existing feature does not function as intended label Nov 30, 2026
@wpmobilebot

wpmobilebot commented Nov 30, 2026 •

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/956")

Built from 3ffcc77

dcalhoun and others added 2 commits November 30, 2026 16:15
Core keeps one content edit for a run of typing, so comparing the edit
with the one seen at the last read hid keystrokes typed after it. Compare
with the edit at open instead, and keep comparing markup once the host
has received edited content, so undoing back to the start is reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Asserting the content edit's type tied a test to how core stores it;
isEditedPostDirty() proves the same precondition. The same-edit check
stays, labelled so a failure points at the test rather than the bridge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Untouched posts can report unsaved changes

2 participants