Repository navigation
Blocks V3: stop marking the post as changed on load - #571
Open
faisalahammad wants to merge 2 commits into
Open
faisalahammad wants to merge 2 commits into
faisalahammad wants to merge 2 commits into
Conversation
- Set hasAcfError only when it changes, as a non persistent update that sends only that key. - Hash a copy of the attributes so the store object is not changed. - Skip writing form data back while the form still has its loaded values, compared with the form's own first serialization. - Count native input and change events in the block form as user interaction. Stored block data is keyed by field name and the form serializes by field key, so the first form serialization always looked like a change and was written back, marking the post as dirty with no edit. Fixes WordPress#556
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @zerodigitaluk. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
A new block has no stored data, so when the form still had its loaded values the fetch sent no field data and the server treated it as a first preview, skipping validation. Required fields on new blocks then no longer blocked publishing. Send the form values with the fetch, without storing them, so the server validates them like before.
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.
Opening a post or template with a Blocks V3 block marked it as changed, with no edit. This came from two updates SCF made to every block on load:
hasAcfErrorwas set on every mount, as a persistent change, even when it was already falsy.data. Stored data is keyed by field name (with_name→ field key) and the form serializes by field key, so the string compare never matched and the same values were written again after the first click anywhere in the editor.What changed
block-edit.jshasAcfErroris only set when it changes. That update is marked not persistent and sends only{ hasAcfError }, so the next real edit is not folded into it (isUpdatingSameBlockAttribute).generateAttributesHash()hashes a copy. Before, it deletedhasAcfErrorand added_acf_contexton the store's own attributes object.setAttributes, it only refreshes the preview. This compares the form with itself, so no name to key mapping or line break handling is needed, and it works for repeaters and groups too.serializeBlockForm()helper, used by the three places that serialized the form.block-form.jsonUntouchedChangeprop. A form change before any interaction (fields setting up) is reported once, so the kept state follows it.input/changeevents now count as interaction, so an edit like a context menu paste is never taken as setup.How to test
tests/e2e/plugins/scf-test-v3-block.phpworks.wp.data.select( 'core/editor' ).isEditedPostDirty()in the console. Before:true. After:false.false, and leaving the page shows no "Leave site?" prompt.Jest tests added in
block-edit.test.jsandblock-form.test.js. The new BlockEdit tests fail on trunk and pass with this change. Full suite: 967 passed.Closes #556
Use of AI Tools
Claude Code was used to help write the fix and tests. I reviewed and tested the changes before submitting.