question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pagination broke after e6357bc

See original GitHub issue

After: https://github.com/marmelab/react-admin/commit/e6357bcc95f53d588a8b44073c1dc22fcbcc9b85 Specifically: https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/controller/useListController.ts#L187-L189

Broke my apps pagination. I wasn’t able to investigate too deeply but I think the root cause may have been that I mutate params inside it’s buildQuery, so I think there may be a cache mismatch or something. defaultTotal was correct, total was undefined in the new change, forcing the page to continually setPage(1) below.

What you were expecting: No breaking change from 3.7.1 to 3.8.1

What happened instead: Pagination broke

Steps to reproduce: I can’t give a full reproduction presently, but a dataProvider’s buildQuery which mutates params of a GET_LIST

Related code: Specifically: https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/controller/useListController.ts#L187-L189

Environment

  • React-admin version: 3.8.1
  • Last version that did not exhibit the issue (if applicable): 3.7.1
  • React version: ^16.9.0
  • Browser: Chrome

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fzaninottocommented, Aug 20, 2020

As in JavaScript, objects are passed by reference, mutating params mutates the original object and may have nasty side effects.

What if you start by cloning the params before passing them to the query? something like:

export const queryBuilder = introspectionResults => (aorFetchType, resourceName, params) => {
+ const myParams = { ...params }; // clone params
  const resource = introspectionResults.resources.find(r => r.type.name === resourceName);
  let result = {};
  switch (aorFetchType) {
   case 'GET_LIST':
   case 'GET_MANY':
   case 'GET_MANY_REFERENCE':
-   params.page = params.pagination.page;
-   params.perPage = params.pagination.perPage;
+   myParams .page = params.pagination.page;
+   myParams .perPage = params.pagination.perPage;

-   if(params.sort && params.sort.field){
-     if(params.sort.field === "id")
-       params.sort.field = "_id";
-     params.sort = `${(params.sort.field).toUpperCase()}_${params.sort.order.toUpperCase()}`
-   }
+   if(params.sort && params.sort.field){
+     if(params.sort.field === "id")
+       myParams.sort.field = "_id";
+     myParams.sort = `${(params.sort.field).toUpperCase()}_${params.sort.order.toUpperCase()}`
+   }

    result =  {
      query: gql`query ${inflection.camelize(resource[aorFetchType].name, true)}($filter: FilterFindMany${resourceName}Input, $sort: SortFindMany${resourceName}Input, $page: Int, $perPage: Int) {
        data: ${inflection.camelize(resource[aorFetchType].name, true)}(filter: $filter, sort: $sort, page: $page, perPage: $perPage) {
          items {
            id: _id
            ${buildFieldList(introspectionResults, resource, aorFetchType, resource)}
          }
          total: count
        }
      }`,
-     variables: params,
+     variables: myParams,
      parseResponse: response => ({
        data: response.data.data.items,
        total: response.data.data.total
      })
    };
    break;
  default:
    return undefined;
  }
  return result;
}
0reactions
fzaninottocommented, Sep 18, 2020

Fixed by #5263

Read more comments on GitHub >

github_iconTop Results From Across the Web

Control pagination - Microsoft Support
On the Format menu, click Paragraph, and then click the Line and Page Breaks tab. Select the Page break before check box. Control...
Read more >
Pagination broken after updates - support - HUGO
Hello, I require some assistance please. I have updated my hugo version and my theme and broke pagination. My webdev knowledge is limited, ......
Read more >
Branches > Pagination is broken (#321196) · Issues - GitLab
Pagination on the bottom of the (active/stale/all) branches page allows you to navigate to previous and next pages.
Read more >
PHP / Laravel 8.0 : UI of link method on Paginator instance is ...
PHP / Laravel 8.0 : UI of link method on Paginator instance is broken after upgrading from version 7.25 · Ask Question. Asked...
Read more >
Managing pagination (or, avoiding page breaks where you ...
The worst way to manage pagination is to do Insert > Page Break (Figure 1). ... so there will never be a page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found