4.0.0-rc.0 - infinite re-render in list component when useResolvedPath is used
See original GitHub issueAdding 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 tohttps://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 inhttps://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:
- Created a year ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I noticed that if I add
disableSyncWithLocation
to my list, then I no longer have this issue. I suspect that the issue is caused bynavigate
call insideuseListParams.ts
; it seems it is trying to navigate to on each re-render, triggering another re-render.Fixed by #7457