Repository navigation
Core Data: Bring back support for nested _fields values - #25083
Conversation
|
Size Change: +19 B (0%) Total Size: 1.2 MB
ℹ️ View Unchanged
|
| // may have included fewer fields properties. | ||
| const field = fields[ f ]; | ||
| if ( ! item.hasOwnProperty( field ) ) { | ||
| const field = fields[ f ].split( '.' ); |
There was a problem hiding this comment.
If this value is left as a string, it matches an undefined value in the state— in my testing I had both meta: { key: 'value' } and 'meta.key': undefined on item, and get matches the string key first, returning undefined. I'm not sure where that other key comes from, but preventing that would be a better fix for this workaround.
Just noting that before #25078 doing this would create subtle bugs where some components could receive "incomplete" entities data. Basically |
|
I tested the PR and it fixed the problem for me 👍🏻 |
Description
Fixes #25078 — The change to
getEntityRecords's use of _fields has broken nested meta field requests. In the API, you can pass nested fields for meta, ex:wp-json/wp/v2/posts?_fields=title,meta.demo,id, and this used to work for the getEntityRecords request.It seems the change in #19498 introduced this:
gutenberg/packages/core-data/src/queried-data/selectors.js
Lines 80 to 82 in 8ba0a42
Which is returning null, because it's testing for
item['meta.key'], rather thanitem.meta.key. This PR switches to using the lodash functionshas,get, andset, which support string keys like that. I've seen some moves away from lodash, but it seems like the most straightforward fix here.How has this been tested?
There's a new test case introduced in
packages/core-data/src/queried-data/test/selectors.jswhich catches this case.You can also test with the code snippet in #25078
Types of changes
Bug fix (non-breaking change which fixes an issue)