Skip to content

Conversation

@PaulREnglish
Copy link
Contributor

What?

No issue number, was easier just to create the PR

Why?

There is a bug with the setupEditor dispatcher. If you pass a non-iterable edit, JS encounters an error preventing the edits from being carried out.

The issue comes from this line:

The parameters of the callback should not be destructured from an array but taken as separate arguments. See the JS documentation.

How?

Remove the square brackets as we should not be using array destructuring for the params.

Testing Instructions

Note that the bug only appears when you pass only non-iterable edits like null or numbers. If you include any edits that are iterable, the bug may not appear.

  1. Create a new draft post
  2. Run
  wp.data.dispatch('core/editor').setupEditor( wp.data.select('core/editor').getCurrentPost(), { author: 2 } )
  1. There should be no JS error.
  2. Check that the edit is applied by running:
  wp.data.select('core').getEditedEntityRecord('postType', 'post', wp.data.select('core/editor').getCurrentPostId())

Screenshots or screencast

Before

Screen.Capture.on.2025-11-11.at.16-20-36.mp4

After

Screen.Capture.on.2025-11-11.at.16-21-15.mp4

@github-actions
Copy link

github-actions bot commented Nov 11, 2025

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: PaulREnglish <bbpaule@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

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

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 11, 2025
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @PaulREnglish! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Package] Editor /packages/editor labels Nov 11, 2025
@Mamaduka
Copy link
Member

Good catch, @PaulREnglish!

I can confirm the bug; however, the proposed fix doesn't exactly resolve the issue. If we change the arguments for Array.some, the edit will become index, which is usually the second argument for similar array callbacks.

What that condition is trying to check is whether any edit is different from the original post object. I think the problem here is that someone accidentally used Object.values instead of Object.entries. Switching to the latter should fix the error and the check.

This is probably a regression after #35929.

diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js
index 81b96e827c..829976b7c1 100644
--- a/packages/editor/src/store/actions.js
+++ b/packages/editor/src/store/actions.js
@@ -62,7 +62,7 @@ export const setupEditor =
 		}
 		if (
 			edits &&
-			Object.values( edits ).some(
+			Object.entries( edits ).some(
 				( [ key, edit ] ) =>
 					edit !== ( post[ key ]?.raw ?? post[ key ] )
 			)

@PaulREnglish
Copy link
Contributor Author

Good catch, @PaulREnglish!

I can confirm the bug; however, the proposed fix doesn't exactly resolve the issue. If we change the arguments for Array.some, the edit will become index, which is usually the second argument for similar array callbacks.

What that condition is trying to check is whether any edit is different from the original post object. I think the problem here is that someone accidentally used Object.values instead of Object.entries. Switching to the latter should fix the error and the check.

This is probably a regression after #35929.

diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js
index 81b96e827c..829976b7c1 100644
--- a/packages/editor/src/store/actions.js
+++ b/packages/editor/src/store/actions.js
@@ -62,7 +62,7 @@ export const setupEditor =
 		}
 		if (
 			edits &&
-			Object.values( edits ).some(
+			Object.entries( edits ).some(
 				( [ key, edit ] ) =>
 					edit !== ( post[ key ]?.raw ?? post[ key ] )
 			)

Thanks for taking a look and the detailed explanation!

I've reverted my original proposed fix and implemented the Object.entries change.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks for contributing, @PaulREnglish!

@Mamaduka Mamaduka merged commit 888cf2e into WordPress:trunk Nov 12, 2025
34 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.1 milestone Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Editor /packages/editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants