Skip to content

Core Data: Prevent unchanged synced records from being marked as edited - #81289

Draft
tyxla wants to merge 1 commit into
trunkfrom
try/prevent-false-unsaved-changes
Draft

Core Data: Prevent unchanged synced records from being marked as edited#81289
tyxla wants to merge 1 commit into
trunkfrom
try/prevent-false-unsaved-changes

Conversation

@tyxla

@tyxla tyxla commented Aug 6, 2026

Copy link
Copy Markdown
Member

What?

Prevents synced entity updates from marking a record as edited when the incoming values are unchanged.

See #79776.

Why?

The unsaved-changes warning checks Core Data for dirty entity records. Synced updates could bypass the usual unchanged-value filtering and create an edit even when the incoming data matched the persisted record, causing a false leave-page warning.

How?

Normalize synced edits against the persisted entity record before dispatching them.

Unchanged updates are ignored, while genuine remote changes are still applied. The implementation also preserves the case where a synced update restores the persisted value and needs to clear an existing local edit.

Testing Instructions

  1. Confirm all tests pass.
  2. Create or open a post and wait until it is saved.
  3. Leave the editor open without making further changes, then close the tab.
  4. Confirm the browser does not show an unsaved-changes warning.
  5. Open another post, make an actual edit, and close the tab without saving.
  6. Confirm the unsaved-changes warning still appears.

Testing Instructions for Keyboard

There are no user-interface changes.

Screenshots or screencast

Not applicable.

Use of AI Tools

Codex was used to investigate the issue and assist with the implementation, tests, and PR description. The resulting changes were reviewed and verified by the author.

@tyxla tyxla self-assigned this Aug 6, 2026
@tyxla tyxla added [Type] Enhancement A suggestion for improvement. [Package] Core data /packages/core-data labels Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Size Change: +49 B (0%)

Total Size: 7.81 MB

📦 View Changed
Filename Size Change
build/scripts/core-data/index.min.js 36.9 kB +49 B (+0.13%)

compressed-size-action

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Flaky tests detected in 0d6c8e7.
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/31110413426
📝 Reported tests:

three users concurrently edit a large post with diverse blocks in /test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Save draft' })

    at Editor.saveDraft (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/save-draft.ts:14:4)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:563:16

@youknowriad youknowriad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is a good idea, but I thought we were doing it already. So I'm going to do some digging to check whether this is redundant code or not.

@youknowriad

Copy link
Copy Markdown
Contributor

The sync manager does this

// Determine which synced properties have actually changed by comparing
// them against the current edited entity record.
const changes = syncConfig.getChangesFromCRDTDoc(
	ydoc,
	await handlers.getEditedRecord()
);

const changedKeys = Object.keys( changes );

if ( 0 === changedKeys.length ) {
	return;
}

I can't tell for sure how redundant is that code with the code you added.

@Mamaduka

Mamaduka commented Aug 7, 2026

Copy link
Copy Markdown
Member

I think this overlaps with #79213. We already landed a similar fix for non-RTC environments - #77100.

@tyxla

tyxla commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

Happy to drop or move with it - let me know.

It's a bit trickier since we might be dealing with situations that we don't have clear reproduction steps for.

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

Labels

[Package] Core data /packages/core-data [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants