Skip to content
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

getEntityRecords returns null after requesting an "invalid" page #38823

Open
davilera opened this issue Feb 15, 2022 · 6 comments
Open

getEntityRecords returns null after requesting an "invalid" page #38823

davilera opened this issue Feb 15, 2022 · 6 comments
Labels
[Package] Core data /packages/core-data [Type] Bug An existing feature does not function as intended

Comments

@davilera
Copy link
Contributor

Description

getEntityRecords should return an array of entities (assuming the resolution is finished) that match the queried criteria. However, it sometimes returns null incorrectly.

As far as I can tell, it returns null when:

  • requesting a taxonomy (I've only tested category and post_tag)
  • there’s up to n pages of entities
  • the requested page is n+1 (results in the empty array [])
  • followed by a new request with page n (always results in null)

Note. This does not occur with postType post.

Step-by-step reproduction instructions

  1. Let’s assume your WordPress site has two categories only.
  2. While in Gutenberg, open the browser's developer tools and run:
wp.data.select( 'core' ).getEntityRecords(
  'taxonomy',
  'category',
  { page: 1 }
)

At first, it returns null. After a couple of seconds, when the resolver has finished, it returns a list of two elements: the two categories we created/had in (1).

  1. Request the second page:
wp.data.select( 'core' ).getEntityRecords(
  'taxonomy',
  'category',
  { page: 2 }
)

We know there's only two categories, so the second page eventually results in the empty array [].

  1. Request the first page again.
wp.data.select( 'core' ).getEntityRecords(
  'taxonomy',
  'category',
  { page: 1 }
)

It should return the list of categories we saw in (2), but the snippet now returns null.

This also occurs if we skip step 2.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 5.9
  • Gutenberg 12.5.4

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

@Mamaduka Mamaduka added [Package] Core data /packages/core-data Needs Testing Needs further testing to be confirmed. labels Feb 15, 2022
@annezazu
Copy link
Contributor

cc @kevin940726 curious for your thoughts here based on the PR that seems to have made this change: #36984

@katag9k
Copy link

katag9k commented Feb 16, 2022

I have run into a smiliar issue where wp.data.select('core').getEntityRecords('taxonomy', 'category', { per_page: 100 }); returns [] in Gutenberg WP 5.8.3 but in Gutenberg WP 5.9.0 it returns null and once in a while it will return []

function customizeCategorySelector(PostTaxonomies) {
  
  return function (props) {
    if (props.slug === 'category') {
      var categories = getEntityRecords('taxonomy', 'category', { per_page: 100 });
      console.log(categories);
    }
  };
}

wp.hooks.addFilter('editor.PostTaxonomyType', 'taxonomy_enqueue', customizeCategorySelector);

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Aug 25, 2022
@Thelmachido
Copy link

There hasn't been much activity on this issue in a while, are you able to take a look at this @kevin940726

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 15, 2022
@Thelmachido Thelmachido added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 29, 2022
@Mamaduka
Copy link
Member

The issue was reviewed in today's Editor Bug Scrub and has been confirmed.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended and removed Needs Testing Needs further testing to be confirmed. [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. labels Oct 11, 2022
@kevin940726
Copy link
Member

Hi there! Sorry for the late reply! I was busy with other things and forgot about the pings 🙇 (Thanks for re-pinging me though!)

I'm not sure if this bug is related to #36984 though. I'm able to reproduce this bug even after reverting that commit.

I don't have the time to investigate this at the time, unfortunately. Maybe git bisect would help pinpoint the exact commit? I'd love to help investigate this once I have the time though!

@codal-crathod
Copy link

I have run into a similar issue where wp.data.select('core').getEntityRecords('taxonomy', 'category', { per_page: 100 }); returns[]in Gutenberg and it returns null.

I am using jQuery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants