-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core Data: Fix errors when the entities list doesn't contain config key #62346
Conversation
Size Change: +9 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
This comment was marked as outdated.
This comment was marked as outdated.
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. |
0011ca6
to
105935f
Compare
@@ -110,7 +110,8 @@ export function items( state = {}, action ) { | |||
[ context ]: { | |||
...state[ context ], | |||
...action.items.reduce( ( accumulator, value ) => { | |||
const itemId = value[ key ]; | |||
const itemId = value?.[ key ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the proposed changes look mostly safe, I wasn't able to reproduce the original error, so I can't confirm that this PR resolves it. I've been following the testing instructions from this PR on trunk
, but no error appears. Any idea what I might be missing?
@@ -232,7 +233,7 @@ const receiveQueries = compose( [ | |||
return { | |||
itemIds: getMergedItemIds( | |||
state?.itemIds || [], | |||
action.items.map( ( item ) => item[ key ] ), | |||
action.items.flatMap( ( item ) => item?.[ key ] ?? [] ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't action.items
be an array of objects? If that's the case, it feels odd if item?.[ key ]
falls back to an empty array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line extracts the nextItemIds
array. It's usually an array of key
items. When every key is undefined
we want to pass an empty array.
This flatMap
pattern is from MDN docs. It's the same as items.map( ( item ) => item?.[ key ] ).filter( ( itemId ) => itemId !== undefined );
Should I use explicit iteration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming. I think this is too idiomatic for most tastes though - I know the pattern and still didn't think of it when I first saw it. I think when one sees .flatMap()
they expect this works with nested arrays, and this isn't the case here, so it could create false expectations. The fact that this area of the code isn't properly typed doesn't make it better. So yes, if I could choose, I'd prefer being more explicit here.
Correct, when I add logging there, I see the error logged, but I still don't understand in what circumstances it will actually be manifested as an error - it's supposed to be caught there, no? |
The error can occur when a response for The example site entity used here returns a single object with properties for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look safe and good to go 👍
Thanks @Mamaduka 🚀
Flaky tests detected in cfe1d0f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9399454129
|
cfe1d0f
to
10a0ac2
Compare
Worth backporting? |
This is probably not a new bug, but it's worth backporting alongside the #62322. |
…ey (#62346) Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mr2P <mr2p@git.wordpress.org>
…ey (#62346) Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mr2P <mr2p@git.wordpress.org>
…ey (WordPress#62346) Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mr2P <mr2p@git.wordpress.org>
This was cherry-picked to the wp/6.6 branch. |
What?
Closes #62311.
PR fixes errors when data returned by the endpoint for
getEntityRecords
doesn't contain config or defaultkey
property.Testing Instructions
wp.data.select( 'core' ).getEntityRecords( 'root', 'site' );.
wp.data.select( 'core' ).getResolutionError( 'getEntityRecords', [ 'root', 'site' ] );
.Testing Instructions for Keyboard
Same.