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

[useDataGrid] Unable to change filter when page is loading #329

Open
AleksandarDev opened this issue Feb 5, 2024 · 0 comments
Open

[useDataGrid] Unable to change filter when page is loading #329

AleksandarDev opened this issue Feb 5, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@AleksandarDev
Copy link
Member

AleksandarDev commented Feb 5, 2024

Problem

The following if statement blocks loading new page if page is already loading.

    const handleLoadPage = useCallback(async (page: number, clearCache: boolean) => {
        if (loading.includes(page)) return;

This makes pages not load on filter changes if loading is longer than expected, for example:

  • Loading page 1...
  • Change filter/order/... -> triggers handleLoadPage bug ignored
  • Loaded page 1

Proposed solution

This line was added to reduce number of repeated requests during table re-rendering when page is already loading - bad implementation.

Always load last requested page even if already loading, discard old page load data when promise resolved and only keep last requested.

useEffect(() => {

  let ignore = false;

  try {
      const data = await getData();
      if (!ignore) {
          setData(data);
      }
  }
  catch(err) {
      if (!ignore) {
          throw err;
      }
  }


  return () => { ignore = true; };

}, [prop1, prop2, prop3]);
@AleksandarDev AleksandarDev added bug Something isn't working good first issue Good for newcomers labels Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant