Closed philbuchanan closed 3 years ago
Thanks for reporting this. From what I can see, the REST API returns the items that exist, but then getEntityRecords
at some point filters them out. Seems like an unexpected result, so I'd consider it a bug.
I think this line is the culprit for this issue:
This check will abort the loop and return null
when we have itemId (from includes) but not the actual item in the state.
The fix seems easy, but I want to do more tests before creating PR to avoid regressions.
The PR is ready for review #34034.
Also wp.data.select( 'core' ).getMediaItems( {include: ids } ) returns NULL if one of the ids does not exist any more.
Hi, @studionenontwerp
This issue should be fixed in the latest Gutenberg plugin and will ship with WP 5.9.
P.S. wp.data.select( 'core' ).getMediaItems( {include: ids } )
might return null
on first invocation, if data isn't in state. Calling it second time will return results. This is automatically handled by useSelect
hook.
Description
When using the
include
parameter withgetEntityRecords
, if one of the specific posts to include doesn't exist, it never returns anything.Step-by-step reproduction instructions
See code below.
Expected behaviour
I would expect an array with objects for the IDs that do exist.
Actual behaviour
As far as I can tell, nothing is ever returned.
Code snippet (optional)
I am using this in the
edit
function of a custom block:If the
ids
array contains only media item IDs that exist, it returns an array of media objects as expected. However, if theids
array contains an ID of a media item that doesn't exist (for example, you permanently delete that media item), it never returns anything—theimages
variable never gets updated.If I use
apiFetch
instead, it does return an array of media objects, with the invalid one removed:I would expect
getEntityRecords
to behave similar toapiFetch
in this regard.WordPress information
Device information