Skip to content
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

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ];
Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out that undefined is a "valid" item ID, and site settings are keyed using it.

Screenshot

CleanShot 2024-06-06 at 00 13 33


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
Loading