-
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: selectors return stale data despite different query parameters #56355
Comments
I was having another look at this and I think I've narrowed it down to the
For example, requesting
So that's why What If If it knew that a corresponding query had already been resolved, it could then confidently return as many as it can find, e.g., the full set of 5 records for the page, or, if it's reached the last page, in a set with < 5 records. |
I have similar issue in latest WordPress 6.5.4. Calling getEntityRecords returns values only from store. Not from actual API call. Assume I Have a few post tags registered. // First load
// API call. Promise return null
await wp.data.select('core').getEntityRecords('taxonomy', 'post_tag', {per_page: 2})
// No API call. Promise return array of 2 items
await wp.data.select('core').getEntityRecords('taxonomy', 'post_tag', {per_page: 2})
// Attempt to load next page
// API call. Promise return an empty array
await wp.data.select('core').getEntityRecords('taxonomy', 'post_tag', {per_page: 2, page: 2})
// No API call. Promise return array of 2 items
await wp.data.select('core').getEntityRecords('taxonomy', 'post_tag', {per_page: 2, page: 2}) |
@kozack-webspark Thanks for the report. Not sure if this helps, but there is a 'resolveSelect` selector that will return the result of any resolved fetch promises: await wp.data.resolveSelect('core').getEntityRecords('taxonomy', 'post_tag', {per_page: 2}) |
Description
Unresolved core data selectors will return
null
if records are not found in state. They'll then go off and "resolve" the query (fetch the data from the API) and update the state.When using query params such as
per_page
— params that normally should trigger a new API call given that it can request records not yet available in the state — the selectors will not returnnull
but return whatever it finds in the state until the resolvers are done.From what I can gather, the
queries
reducer state for each entity creates "stableKeys" to cache IDs for certain queries. Currently only_fields
andincludes
queries are cached, otherwise the key is""
.Props to @andrewserong for finding and reporting here: #54046 (review)
Step-by-step reproduction instructions
Make sure you have a few posts or pages or other entities saved.
In your browser's console, fetch those entities:
What I expected
For commands 3 and 4, we'd expect either
null
or[]
or some other result to indicate that the selector cannot find these records.Instead it returns the last known query.
Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: