-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CustomRoutes don't work without resources #7598
Comments
Hi @RWOverdijk Have you seen this PR #7539 and particularly this comment and this file? I believe this is exactly about the problem you are having. If ever this does not work for you, then I believe adding an empty resource like you do is the quickest and easiest way to achieve what you want, because otherwise it would required some more important changes in the way we load the resources and routes and handle the ready screen imo. |
Pfff, again? 😅 I did see that. In fact, it's based on an issue I reported (seeing not only on logout but also on dynamic resources not working). #7527 that's me. But it's not what I'm reporting. Seeing that screen is fine. It has a purpose. Seeing that screen even though there are routes is not fine. Also, after loading the resources it doesn't jump back to actually show anything. Try it, the sandbox is there. The loading screen doesn't go away. This is a specific bug with a reproducible path. Something is skipping custom routes if there are no resources. That's it. That's the bug. If this is "expected behaviour" then I don't know anymore. |
I have to admit I did not try your codesandbox right away, because I thought the problem was so similar it might just be it. My bad 😅 . Anyway, I was not suggesting that this is the expected behaviour, but rather than your use case is currently not really supported by react-admin, at least without some customization. |
That's a bug IMO. We shouldn't force you to have resources if you at least provided some custom routes. |
It's always such an adventure to post issues on this repo, even 6 years later it's still a wild ride. Anyway, I did some detective work.
So the only time this Ready component should be rendered, I think, is when there are no children at all. The default screen says as much (start creating resources). If it's truly meant to display a loading screen due to dynamic resources for example that should come from the outside-in, not the other way around. By this I that the person dynamically loading resources should provide a loading indicator for these cases. On a side-note, also maybe not name the prop "ready" in that case. That's a strange name for a loading indicator. Anyway, tl;dr; the conditionals (based on point 1 and point 2 above) that check for a function appear to be the cause. |
Hi all, thanks for the support. With the fix is it now possible to initially not have resources (dynamically async loaded) but render custom page/routes (e.g. welcome page) including react-admin layout for login e.g.? |
It took me a while to reproduce this one but I think I found it.
When you have no resources (either because you have no permissions to see them or simply because you don't) CustomRoutes don't get registered outside of the permission function inside of
<Admin />
It's easier to just show what I mean: https://codesandbox.io/s/sparkling-wind-5sq5u9?file=/src/index.tsx
In render() replace AppWorking with AppBroken and hit the refresh icon in the preview on the right (make sure the preview url path is set to /custom)
Note: I used
<Admin />
and had the same result. I just left in AdminContext and AdminUI to more accurately reflect my actual code.What you were expecting:
I was expecting custom routes to be registered regardless of permission/resource state.
What happened instead:
No route registered.
Steps to reproduce:
https://codesandbox.io/s/sparkling-wind-5sq5u9?file=/src/index.tsx
In render() replace AppWorking with AppBroken and hit the refresh icon in the preview on the right.
Related code:
See sandbox
Context:
My permissions are loaded async. React-admin doesn't handle this very well so hacked in a reload of the page after login to make sure the proper resources show up.
I'll be sending out invite emails to users. The link should go to /accept-invite, which doesn't require you to be logged in. It lives independent of the rest of the app.
When it's the first time visiting the dashboard you're not logged in and so there are no resources. This causes the "ready" component to show.
Workaround/hack:
The only way I can work around this is by adding an empty resource like so:
<Resource name="hack" />
The text was updated successfully, but these errors were encountered: