Skip to content

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

@AleksandarDev

Description

@AleksandarDev

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]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions