Skip to content
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

Closed
RWOverdijk opened this issue Apr 29, 2022 · 7 comments · Fixed by #7609
Closed

CustomRoutes don't work without resources #7598

RWOverdijk opened this issue Apr 29, 2022 · 7 comments · Fixed by #7609
Labels

Comments

@RWOverdijk
Copy link
Contributor

RWOverdijk commented Apr 29, 2022

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" />

@RWOverdijk RWOverdijk changed the title CustomRoutes don't work without resource CustomRoutes don't work without resources Apr 29, 2022
@slax57
Copy link
Contributor

slax57 commented Apr 29, 2022

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.

@RWOverdijk
Copy link
Contributor Author

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.

@slax57
Copy link
Contributor

slax57 commented Apr 29, 2022

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.
IMO having a "hacky" resource like you did is not too bad of a solution, but if you are unsatisfied with it, we would gladly welcome a PR improving this so that you don't need this "hack" no more.

@djhi djhi reopened this Apr 29, 2022
@djhi
Copy link
Collaborator

djhi commented Apr 29, 2022

That's a bug IMO. We shouldn't force you to have resources if you at least provided some custom routes.

@djhi djhi added the bug label Apr 29, 2022
@RWOverdijk
Copy link
Contributor Author

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.

  1. A status is being created here
  2. And again here
  3. Which takes us here
  4. It never even gets to registering CustomRoutes (couple lines below).

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.

@magicpai
Copy link

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.?
Sorry if here is not the right forum for such follow-up question.

@slax57
Copy link
Contributor

slax57 commented Dec 13, 2022

@magicpai I believe that with #8490 it will be possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants