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.

4.0.0-rc.0 - infinite re-render in list component when useResolvedPath is used

See original GitHub issue

Adding const resolved = useResolvedPath('') cases the following issues:

  • List component causes infinite re-render.
  • web page URL is automatically updated to include URL parameters (when loading a page by link https://vw0pg1.sse.codesandbox.io/#/posts, the browser redirects to https://vw0pg1.sse.codesandbox.io/#/posts?displayedFilters=%7B%7D&filter=%7B%7D&order=ASC&page=1&perPage=10&sort=id)

What you were expecting: useResolvedPath usage in list component should not impact react-admin behavior:

  • when I enter https://vw0pg1.sse.codesandbox.io/#/posts to blank page in browser, it should stay in https://vw0pg1.sse.codesandbox.io/#/posts without adding parameters
  • the page should not go into infinite re-render loop

What happened instead:

Steps to reproduce:

Related code:

https://codesandbox.io/s/winter-sky-vw0pg1?file=/src/posts/PostList.tsx:707-1355

Notice how console.log keeps printing messages, and also render count keeps updating.

If I comment out lines that cause issues, then react-admin starts behaving properly

export const PostList = (props: any): JSX.Element | null => {
  const ref = React.useRef(1);
  ref.current = ref.current + 1;

  const basename = useBasename();
  const resolvedPath = useResolvedPath(""); // THIS LINE CAUSES ISSUES
  console.log({ basename, resolvedPath });  // THIS LINE CAUSES ISSUES

  const filters = [
    <TextInput
      key="1"
      label="id"
      source="id"
      alwaysOn
      sx={{ width: "100%", minWidth: "350px" }}
    />
  ];

  return (
    <Fragment>
      <div>{ref.current}</div>
      <List {...props} filters={filters}>
        <Datagrid rowClick="edit">
          <TextField source="id" label="ID" />
        </Datagrid>
      </List>
    </Fragment>
  );
};

Other information:

Environment

  • React-admin version: 4.0.0-rc.0
  • Last version that did not exhibit the issue (if applicable):
  • React version:
  • Browser:
  • Stack trace (in case of a JS error):

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
panfivacommented, Mar 30, 2022

I noticed that if I add disableSyncWithLocation to my list, then I no longer have this issue. I suspect that the issue is caused by navigate call inside useListParams.ts; it seems it is trying to navigate to on each re-render, triggering another re-render.

0reactions
fzaninottocommented, Apr 1, 2022

Fixed by #7457

Read more comments on GitHub >

github_iconTop Results From Across the Web

Infinite re-render in functional react component - Stack Overflow
The effect hook runs every render cycle, and one without a dependency array will execute its callback every render cycle.
Read more >
How to stop re-rendering lists in React? - Alex Sidorenko
Components always re-render. First, let's simplify our example by removing all props from the Item . We will still update the parent state...
Read more >
Issue with infinite rerendering when update state via context ...
I have a parent WORKSPACE component that has 2 child components, ... in the list, but when trying to add a 2nd, I...
Read more >
react-router-dom: Versions - Openbase
This pre-release brings the data abstractions from Remix to React Router. There will be more complete release notes for the v6.4 final release....
Read more >
Preventing infinite re-renders when using useEffect and ...
Changing state will always cause a re-render. ... you don't include a dependency array when using useEffect to fetch data, and use useState...
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