Skip to content

Commit

Permalink
Core Data: Allow 'null' as raw attribute value (#69257)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: TimothyBJacobs <[email protected]>
  • Loading branch information
4 people authored Feb 20, 2025
1 parent 67a07a7 commit 1756bac
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ export const getRawEntityRecord = createSelector(
// Because edits are the "raw" attribute values,
// we return those from record selectors to make rendering,
// comparisons, and joins with edits easier.
accumulator[ _key ] = record[ _key ]?.raw ?? record[ _key ];
accumulator[ _key ] =
record[ _key ]?.raw !== undefined
? record[ _key ]?.raw
: record[ _key ];
} else {
accumulator[ _key ] = record[ _key ];
}
Expand Down
42 changes: 42 additions & 0 deletions packages/core-data/src/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,48 @@ describe( 'getRawEntityRecord', () => {
},
} );
} );
it( 'should allow `null` as raw value', () => {
const state = deepFreeze( {
entities: {
config: [
{
kind: 'someKind',
name: 'someName',
rawAttributes: [ 'title' ],
},
],
records: {
someKind: {
someName: {
queriedData: {
items: {
default: {
post: {
title: {
raw: null,
rendered: 'Placeholder',
},
},
},
},
itemIsComplete: {
default: {
post: true,
},
},
queries: {},
},
},
},
},
},
} );
expect(
getRawEntityRecord( state, 'someKind', 'someName', 'post' )
).toEqual( {
title: null,
} );
} );
} );

describe( 'getEntityRecords', () => {
Expand Down

0 comments on commit 1756bac

Please sign in to comment.