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

4.0.2 > 4.1.0 breaking changes #7725

Closed
RWOverdijk opened this issue May 20, 2022 · 7 comments · Fixed by #7731 or #7737
Closed

4.0.2 > 4.1.0 breaking changes #7725

RWOverdijk opened this issue May 20, 2022 · 7 comments · Fixed by #7731 or #7737
Labels

Comments

@RWOverdijk
Copy link
Contributor

RWOverdijk commented May 20, 2022

What you were expecting:

I just updated to 4.1.0 and notice some breaking changes.

  1. The permission function provided as a child to now gets called with undefined the first time (broke my dashboard).
  2. It also requires the function to be a promise now.

Both of these weren't an issue on 4.0.2.

I fixed these issues easily by adding a simple if (!p) return null at the top of the function and making it async. Visually:

<Admin>
  {async permissions => { // < added async
    if (!permissions) return null; // < added check

    // ...
  }}
</Admin>

The reason I am still writing this issue is because this version is tagged as a minor version and so it should have been backwards compatible. I thought you might want to know.

Update: I just tested the rest and all my other issues were fixed in this release though, so I am actually really happy with 4.1.0

@fzaninotto
Copy link
Member

Hi, and thanks for your feedback. This is likely linked to changes introduced in 4.0.3 (#7606, #7609).

Regarding your second point, I can't reproduce it in the simple example codesandbox, which uses a function that does not return a Promise.

https://codesandbox.io/s/github/marmelab/react-admin/tree/master/examples/simple

Could you please build a repro based on that CodeSandbox?

Regarding your first point, I'm not sure this is a bug - we'll also need a repro to see.

Thanks in advance

@RWOverdijk
Copy link
Contributor Author

RWOverdijk commented May 20, 2022

@fzaninotto I can't (unfortunately no time). But:

useConfigureAdminRouterFromChildren.tsx:116 TypeError: Cannot read properties of null (reading 'then')

image

this is in useConfigureAdminRouterFromChildren.tsx

I don't know why the sandbox doesn't have the issue.

Feel free to close this if this isn't enough info, no hard feelings 😄

Update: actually, this shows the issue. It's checking for .then on null. I think it should maybe be ?.then

@fzaninotto
Copy link
Member

That's the problem: the function shouldn't return null, but a list of children. I believe this is due to the fact that, if you don't have permissions, you return nothing.

I managed to reproduce the second error : https://codesandbox.io/s/wonderful-lichterman-lez2zo?file=/src/authProvider.tsx

So I'm marking this as a bug - But I'm not sure what the admin should show when the function returns nothing.

@RWOverdijk
Copy link
Contributor Author

@fzaninotto The first call to the permissions function (with undefined) used to not happen, I think that's why I noticed the null issue now. If you don't have permissions you're not allowed to see any of the resources. When you log in, I can finally start filtering resources. But returning null from a promise is allowed and doesn't break, so it's not fatal. Just interesting 😄

@RWOverdijk
Copy link
Contributor Author

Hm, something does seem broken. It's no longer redirecting me to /login when I'm not logged in, for some reason. I'll reply here once I find out what the problem is.

@fzaninotto
Copy link
Member

fzaninotto commented May 23, 2022

I'm reopening the issue as @djhi 's fix only concerns regression #2 - regression #1 is still not fixed.

  1. The permission function provided as a child to now gets called with undefined the first time (broke my dashboard).
  2. It also requires the function to be a promise now.

@fzaninotto fzaninotto reopened this May 23, 2022
@RWOverdijk
Copy link
Contributor Author

I'm not able to figure out what's going on. It's calling the permission method twice and if neither returns anything it's not sending me to login. It's hard to share the code but I "fixed" (hack) it like so:

<Admin>
    {async p => {
        try {
          await Auth.currentSession();
        } catch (error) {
          if (!window.location.hash.startsWith('#/accept-invite?')) window.top.location = '/#/login'
        }

        if (!p) return null;
    }}
</Admin>

If not authenticated, and url is not something that is allowed send to login. If !p (permissions) return null and wait until they do exist. I think I can share the project with you directly, I'm just not allowed to just upload it to github because of contracts.

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