Skip to content

Commit

Permalink
Core Data: Fix errors when the entities list doesn't contain config k…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
4 people authored Jun 6, 2024
1 parent 91835a5 commit f7a3c65
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/core-data/src/queried-data/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];

accumulator[ itemId ] = conservativeMapItem(
state?.[ context ]?.[ itemId ],
value
Expand Down Expand Up @@ -164,7 +165,7 @@ export function itemIsComplete( state = {}, action ) {
[ context ]: {
...state[ context ],
...action.items.reduce( ( result, item ) => {
const itemId = item[ key ];
const itemId = item?.[ key ];

// Defer to completeness if already assigned. Technically the
// data may be outdated if receiving items for a field subset.
Expand Down Expand Up @@ -232,7 +233,7 @@ const receiveQueries = compose( [
return {
itemIds: getMergedItemIds(
state?.itemIds || [],
action.items.map( ( item ) => item[ key ] ),
action.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),
page,
perPage
),
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function entity( entityConfig ) {
const nextState = { ...state };

for ( const record of action.items ) {
const recordId = record[ action.key ];
const recordId = record?.[ action.key ];
const edits = nextState[ recordId ];
if ( ! edits ) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export const getEntityRecords =
if ( ! query?._fields && ! query.context ) {
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
const resolutionsArgs = records
.filter( ( record ) => record[ key ] )
.filter( ( record ) => record?.[ key ] )
.map( ( record ) => [ kind, name, record[ key ] ] );

dispatch( {
Expand Down

1 comment on commit f7a3c65

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in f7a3c65.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9403036203
📝 Reported issues:

Please sign in to comment.