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

CoreAdminUI with dynamic list of Resource does not render in production build #4322

Closed
smeng9 opened this issue Jan 20, 2020 · 3 comments · Fixed by #4432
Closed

CoreAdminUI with dynamic list of Resource does not render in production build #4322

smeng9 opened this issue Jan 20, 2020 · 3 comments · Fixed by #4432
Assignees
Labels

Comments

@smeng9
Copy link
Contributor

smeng9 commented Jan 20, 2020

What you were expecting:
I expect the production build would render in the same way as in development server

What happened instead:
After fresh yarn && yarn build, the production build renders as a white screen.

Steps to reproduce:

First I got the tutorial example from here, the tutorial is able to render in both development server and build
https://github.com/marmelab/react-admin/tree/master/examples/tutorial

Then I added the third code snippet in CoreAdmin.tsx to make it support dynamic list of Resources
https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/core/CoreAdmin.tsx

The final code is on code sandbox. I tried to make the example simple, so I only modified App.js by directly put the <Resources> as children of <CoreAdminUI>
https://codesandbox.io/s/ecstatic-ganguly-j4e35

The code above is able to run on codesandbox, the development server, but not able to run after build. I used serve -s build to serve the transpiled code.
I believe it can be reproduced and it is not a build toolchain issue since the original tutorial example is able to run after build.

Related code:

The issue should be reproduced locally using yarn build

https://codesandbox.io/s/ecstatic-ganguly-j4e35

Other information:

After modified my code to load a dynamic list of resources in the project, I also experienced similar translation broken issue in #3000 and #3007 for the production build but not on development server.

Environment

  • React-admin version: ^3.0.0
  • Last version that did not exhibit the issue (if applicable): 2.9.9 (This version does not have CoreAdminContext and CoreAdminUI)
  • React version: ^16.9.0
  • Browser: Firefox 71
  • Stack trace (in case of a JS error): The console is empty
@smeng9
Copy link
Contributor Author

smeng9 commented Jan 20, 2020

I noticed there is another similar piece of code snippet in https://github.com/marmelab/react-admin/blob/master/packages/react-admin/src/Admin.tsx
The only difference is CoreAdminContext and CoreAdminUI is replaced by AdminContext and AdminUI.
AdminUI and AdminContext have default props for layout and translation where the Core ones don't. **That is the reason of a white screen and no translation.

I suggest a quick fix for this issue:

  • We can either remove the code snippet in CoreAdmin.tsx and tell user to use code snippet in Admin.tsx
  • Or we can clearly state in documentation that if user want to use CoreAdmin some of the default props are not supplied.
  • We can also move the defaults one layer down

Although I am still not sure why the code here works in development server but not after build https://codesandbox.io/s/ecstatic-ganguly-j4e35

@fzaninotto
Copy link
Member

fzaninotto commented Feb 19, 2020

I don't know why your code works in development - it shouldn't.

You have an authProvider but no loginPage. What happens is that the authProvider finds the user isn't authenticated, and redirects the user to a non-existing login page. Therefore, the screen is blank (because the 404 page is blank in CoreAdminUI).

To make the code work, just import and use AdminUI instead of CoreAdminUI.

For some obscure reason, the copy of a component doesn't work the same in development and in production. The culprit is this code in react-admin:

// in AdminUI.ts
import { CoreAdminUI } from 'ra-core';
import {
    Layout as DefaultLayout,
    Loading,
    Login,
    Logout,
    NotFound,
} from 'ra-ui-materialui';

const AdminUI = CoreAdminUI;

AdminUI.defaultProps = {
    layout: DefaultLayout,
    catchAll: NotFound,
    loading: Loading,
    loginPage: Login,
    logout: Logout,
};

AdminUI.displayName = 'AdminUI';

export default AdminUI;

Because imports are static, this shouldn't modify the defaultProps of CoreAdminUI - and it doesn't in production, which is normal. However, it does in development. Why? this is a mystery that we must solve.

@fzaninotto fzaninotto added the bug label Feb 19, 2020
@fzaninotto fzaninotto self-assigned this Feb 19, 2020
fzaninotto added a commit that referenced this issue Feb 19, 2020
@fzaninotto
Copy link
Member

I confirmed that the aliasing is the issue. Replacing:

const AdminUI = CoreAdminUI;

by

const AdminUI = props => <CoreAdminUI {...props} />;

"fixes" the problem (in your case, that means there is a white screen even in development). I'm opening a PR to push this fix.

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.

2 participants