Skip to content

Block/Tabs: Fix editor dirty state on reload by removing unnecessary mount-time attribute init#78339

Merged
t-hamano merged 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/78337-tabs-block-dirty-editor-state-on-reload
May 16, 2026
Merged

Block/Tabs: Fix editor dirty state on reload by removing unnecessary mount-time attribute init#78339
t-hamano merged 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/78337-tabs-block-dirty-editor-state-on-reload

Conversation

@Mustafabharmal
Copy link
Copy Markdown
Contributor

What?

Removes the useEffect in tabs/edit.js that initialised editorActiveTabIndex via setAttributes on mount.

Closes #78337.

Why?

editorActiveTabIndex has "role": "local" in block.json — it is never serialised to post content. This means it is always undefined when a saved post is reloaded. The useEffect on mount called setAttributes({ 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 editorActiveTabIndex already gracefully handle undefined by falling back to activeTabIndex via ??:

  • tab/edit.js: editorActiveTabIndex ?? activeTabIndex
  • tab-panel/edit.js: editorActiveTabIndex ?? activeTabIndex
  • remove-tab-toolbar-control.js: tabsAttributes?.editorActiveTabIndex ?? tabsAttributes?.activeTabIndex ?? 0

Removing the useEffect means editorActiveTabIndex stays undefined until the user actively clicks a tab, at which point the child blocks already set it correctly via __unstableMarkNextChangeAsNotPersistent.

Testing Instructions

  1. Create a new post.
  2. Insert a Tabs block.
  3. Save or publish the post.
  4. Reload the editor page.
  5. Without making any changes, verify the header shows "Saved" with the checkmark — not "Save draft".
  6. Click between tabs and verify the active tab still switches correctly.
  7. Add/remove tabs and verify they still work correctly.

Screenshots or screencast

Before:

Tab.Block.Testing.mov

After:

Tab.Block.Testing.After.Fix.mov

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label May 15, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added the [Block] Tabs Affects the Tabs Block label May 16, 2026
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

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.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended props-bot Manually triggers Props Bot to ensure the list of props is up to date. labels May 16, 2026
@github-actions github-actions Bot removed the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label May 16, 2026
@t-hamano t-hamano added the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label May 16, 2026
@github-actions github-actions Bot removed the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label May 16, 2026
@t-hamano t-hamano merged commit af94c78 into WordPress:trunk May 16, 2026
56 of 59 checks passed
@github-actions github-actions Bot added this to the Gutenberg 23.3 milestone May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Tabs Affects the Tabs Block [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tabs block keeps post in dirty state after reload without any user changes

2 participants