Loading for lazy-load strategy is not showing in react-router v7
What you were expecting: RA lazy strategy with loading should work properly after update to react-router v7.
What happened instead:
Loading component not initiate in Suspense when update my App to react-router v7.
Steps to reproduce:
- Create router that import lazy components;
- Navigate with slow network to understand the problem, setted in the Browser;
- Loading componente will not be initiated by RA Suspense;
This strategy solved my problem: https://github.com/remix-run/react-router/issues/12474
I think that we can put key inside the Suspense to solve the problem: https://github.com/marmelab/react-admin/blob/377f29f0c4357281838e978fa613acb29c6dbe2b/packages/ra-ui-materialui/src/layout/Layout.tsx#L70
like:
function MyComp() {
const location = useLocation()
return (
<Suspense
fallback={<LoadingComp text="Loading..." />}
key={location.key}
>
<MyAwaitOrUseComp />
</Suspense>
)
}
Other information:
Environment
- React-admin version: 5.8.4
- Last version that did not exhibit the issue (if applicable):
- React version: v18
- Browser: chrome
- Stack trace (in case of a JS error):
We don't lazy load anything in react-admin so I think you're talking about the lazy loading example in our documentation?
My bad, I missed the comment about our Layout. In any case, we use react-router v7 on the ecommerce demo and didn't notice any issue with lazy loading.
Can you provide a reproduction?
I think you can't notice because of the fast server response. Try to simulate the use of a slow internet, the loading component, provided by React Admin never runs. I think that this problem occurs because of the startTransition implemented in react-router v7.
Hey @djhi, did you read my last comment?
Hey @lukascivil, could you setup a reproduction somewhere? A git repo if stackblitz doesn't work