getEntityRecords()
returns stale values when subsequent calls reduce the number of records
#32594
Labels
[Package] Core data
/packages/core-data
[Priority] High
Used to indicate top priority items that need quick attention
[Type] Bug
An existing feature does not function as intended
Description
If you call
select('core').getEntityRecords( .. )
with an argument which causes the number of results in the set to be reduced from its previous value, for example via theinclude
parameter, unexpected stale values will be present at the end of the array.Step-by-step reproduction instructions
See below for what seems to be the minimum code to reproduce the issue as a whole by implementing a filter on the Tags panel.
withSelect()
callback due to the change.ownProps.terms
is an array containing the chosen tag ID. Observe thegetEntityRecords()
resolver fires off a REST API request to fetch the tag by using theinclude
parameter on the endpoint.include
parameter.include
parameter passed togetEntityRecords()
to include one fewer elements that it did previously. Observe the resolver correctly queries for one term ID in the REST API request, but the subsequent return value ofgetEntityRecords()
still contains two values.What appears to be happening is the
getEntityRecords()
resolver iterates the values it receives from the REST API but somehow retains stale values for all subsequent elements in the array instead of discarding them.Code snippet
This is a filter on the Tags panel which calls
getEntityRecords()
inside thewithSelect()
callback. You could manually callgetEntityRecords()
in your console but this demonstrates the problem within the context ofwithSelect()
.WordPress information
The text was updated successfully, but these errors were encountered: