Repository navigation
Conversation
|
Thanks for the PR, and for digging into this. The diagnosis is right - creating the router in the render body is the bug - but The route element is const App = () => {
const [config, setConfig] = useState(null);
useEffect(() => {
fetchConfig().then(setConfig);
}, []);
return (
<Admin dataProvider={dataProvider}>
<Resource name="posts" {...posts} />
{config?.betaEnabled && <Resource name="experiments" {...experiments} />}
</Admin>
);
};With this patch, the The unit test can't catch this, because it counts calls to I've opened #11435 with an alternative: the router is still created once, but the route element reads the children from a context placed above the Your analysis of the root cause is what made that fix straightforward, so thank you for it. |
Problem
Fixes #11431
When
InternalRouterrerenders, it creates a new router instance. During logout, if the<Admin>component rerenders whileauthProvider.logout()is pending, navigation can target an outdated router instance, resulting in a blank page.Solution
Initialize the hash router only once using lazy
React.useState. This prevents the router from being recreated on every render.Added a unit test to verify that rerendering the parent component does not recreate the router.
How To Test
yarn test-unit packages/ra-core/src/routing --runInBandcreateHashRouteris called only once after a parent rerender.Additional Checks
masterfor a bugfix or a documentation fix, ornextfor a feature