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

Release v3.9.5 broke layout prop #5443

Closed
mariaefi29 opened this issue Oct 27, 2020 · 5 comments
Closed

Release v3.9.5 broke layout prop #5443

mariaefi29 opened this issue Oct 27, 2020 · 5 comments

Comments

@mariaefi29
Copy link

mariaefi29 commented Oct 27, 2020

What you were expecting:
On v3.9.4 I used layout prop and passed in it my custom layout component.

What happened instead:
After upgrading to v3.9.5 I started getting the following error and the app stoped working:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Steps to reproduce:
I was able to identify the problem and it turned out to be with a custom layout component.

Related code:
https://codesandbox.io/s/cranky-sanderson-2l2tm?fontsize=14&hidenavigation=1&theme=dark&file=/src/App.tsx

If you comment out the layout component, everything works. If you add it again, the app break with the error that I specified above.

Environment

  • React-admin version: v3.9.5
  • Last version that did not exhibit the issue (if applicable): v3.9.4
  • React version: 17.0.1
  • Browser: Google Chrom
  • Stack trace (in case of a JS error):
    image
@Luwangel Luwangel added the bug label Oct 27, 2020
@Luwangel
Copy link
Contributor

Hi, thanks for reporting this issue. It's probably related to my PR #5421. I let you know as soon as I understand what is wrong.

@Luwangel
Copy link
Contributor

Hi again,

You issue is not related to my changes because they haven't been released yet.

But I found your issue:

Warning: Failed prop type: Invalid prop userMenu of type function supplied to AppBar, expected a single ReactElement.

You need to pass a ReactElement to the userMenu prop.

const MyAppBar = props => <AppBar {...props} userMenu={<MyUserMenu />} />;

Regards,
Adrien

@Luwangel Luwangel removed the bug label Oct 27, 2020
@mariaefi29
Copy link
Author

@Luwangel Oh, thank you so much!!!

@mariaefi29
Copy link
Author

Could you please tell me why in AppBar for example you don't need to pass as a react element?

this works:
return <Layout {...props} appBar={CustomAppBar} />;

@Luwangel
Copy link
Contributor

It's because we use internally createElement for the appBar, and cloneElement for the userMenu. But it's difficult to change it at the moment because it'll introduce a breaking change. We need to think about it for the v4.

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

No branches or pull requests

2 participants