Block/Tabs: Fix editor dirty state on reload by removing unnecessary mount-time attribute init#78339
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
t-hamano
left a comment
There was a problem hiding this comment.
LGTM! This effect is redundant and should be removable without changing the editor's behavior.
As a side note, it would be great if editorActiveTabIndex could be completely removed. Attributes are not intended to indicate the editor's state.
What?
Removes the
useEffectintabs/edit.jsthat initialisededitorActiveTabIndexviasetAttributeson mount.Closes #78337.
Why?
editorActiveTabIndexhas"role": "local"inblock.json— it is never serialised to post content. This means it is alwaysundefinedwhen a saved post is reloaded. TheuseEffecton mount calledsetAttributes({ editorActiveTabIndex: activeTabIndex })without__unstableMarkNextChangeAsNotPersistent, recording a persistent edit every time the editor loaded a post containing a Tabs block. This caused the "Save draft" button to appear instead of the "Saved" checkmark with no user changes.How?
All consumers of
editorActiveTabIndexalready gracefully handleundefinedby falling back toactiveTabIndexvia??:tab/edit.js:editorActiveTabIndex ?? activeTabIndextab-panel/edit.js:editorActiveTabIndex ?? activeTabIndexremove-tab-toolbar-control.js:tabsAttributes?.editorActiveTabIndex ?? tabsAttributes?.activeTabIndex ?? 0Removing the
useEffectmeanseditorActiveTabIndexstaysundefineduntil the user actively clicks a tab, at which point the child blocks already set it correctly via__unstableMarkNextChangeAsNotPersistent.Testing Instructions
Screenshots or screencast
Before:
Tab.Block.Testing.mov
After:
Tab.Block.Testing.After.Fix.mov