-
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: getEditedEntityRecord: do not return empty object #60988
Changes from all commits
4a4ce64
f7319d7
923d1a3
d2fb217
31383d6
3087897
52232e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -846,10 +846,21 @@ export const getEditedEntityRecord = createSelector( | |
kind: string, | ||
name: string, | ||
recordId: EntityRecordKey | ||
): ET.Updatable< EntityRecord > | undefined => ( { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's interesting how the type and docs already accounted for |
||
...getRawEntityRecord( state, kind, name, recordId ), | ||
...getEntityRecordEdits( state, kind, name, recordId ), | ||
} ), | ||
): ET.Updatable< EntityRecord > | false => { | ||
const raw = getRawEntityRecord( state, kind, name, recordId ); | ||
const edited = getEntityRecordEdits( state, kind, name, recordId ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably avoid the |
||
// Never return a non-falsy empty object. Unfortunately we can't return | ||
// undefined or null because we were previously returning an empty | ||
// object, so trying to read properties from the result would throw. | ||
// Using false here is a workaround to avoid breaking changes. | ||
if ( ! raw && ! edited ) { | ||
return false; | ||
} | ||
return { | ||
...raw, | ||
...edited, | ||
}; | ||
}, | ||
( | ||
state: State, | ||
kind: string, | ||
|
@@ -1264,7 +1275,7 @@ export function getReferenceByDistinctEdits( state ) { | |
export function __experimentalGetTemplateForLink( | ||
state: State, | ||
link: string | ||
): Optional< ET.Updatable< ET.WpTemplate > > | null { | ||
): Optional< ET.Updatable< ET.WpTemplate > > | null | false { | ||
const records = getEntityRecords< ET.WpTemplate >( | ||
state, | ||
'postType', | ||
|
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
undefined< EntityRecord >
type exposes a bug in thedocgen
tool. The type in the source isET.Updatable<EntityRecord>
, and is imported withimport type * as ET from './types';
. Apparently the tool is unable to follow the wildcard references.After I change the import to be non-wildcard (
import { Updatable, ... } from './types'
) thendocgen
can process it correctly.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.
Fixing this in #61097.