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

[ButtonBase] Extend error message for invalid component prop #15627

Merged
merged 8 commits into from
May 9, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented May 8, 2019

Closes #15598

Throw a custom error instead of a cryptic Cannot read ownerDocument of null which just points to the console warnings that explain the issue in more details with links to fix prescriptions.

Adds a redirect from https://next.material-ui.com/bug to the bug report issue template.

My preferred solution would be a custom error boundary around all our components that catches and rethrows errors while also prefixing error messages with a hint to the console and helpful links. This would be a dev only boundary which requires some thought about build infra etc. But it's definitely something I want to explore later. For now this custom solution should be sufficient.

@eps1lon eps1lon added docs Improvements or additions to the documentation component: ButtonBase The React component. labels May 8, 2019
@mui-pr-bot
Copy link

mui-pr-bot commented May 8, 2019

@material-ui/core: parsed: +0.07% , gzip: +0.17%
@material-ui/lab: parsed: +0.16% , gzip: +0.33%

Details of bundle changes.

Comparing: 1555e52...78cfcfc

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core +0.07% 🔺 +0.17% 🔺 316,779 317,003 86,501 86,644
@material-ui/core/Paper 0.00% 0.00% 67,859 67,859 20,165 20,165
@material-ui/core/Paper.esm 0.00% 0.00% 61,152 61,152 18,956 18,956
@material-ui/core/Popper 0.00% 0.00% 28,738 28,738 10,349 10,349
@material-ui/core/Textarea 0.00% 0.00% 5,513 5,513 2,384 2,384
@material-ui/core/TrapFocus 0.00% 0.00% 3,744 3,744 1,580 1,580
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 15,960 15,960 5,779 5,779
@material-ui/core/useMediaQuery 0.00% 0.00% 2,106 2,106 974 974
@material-ui/lab +0.16% 🔺 +0.33% 🔺 140,261 140,485 42,708 42,849
@material-ui/styles 0.00% 0.00% 51,344 51,344 15,182 15,182
@material-ui/system 0.00% 0.00% 14,463 14,463 4,180 4,180
Button +0.26% 🔺 +0.53% 🔺 85,558 85,782 25,633 25,770
Modal 0.00% 0.00% 20,342 20,342 6,696 6,696
colorManipulator 0.00% 0.00% 3,904 3,904 1,543 1,543
docs.landing 0.00% 0.00% 51,200 51,200 11,348 11,348
docs.main +0.03% 🔺 +0.05% 🔺 653,992 654,216 205,146 205,247
packages/material-ui/build/umd/material-ui.production.min.js +0.08% 🔺 +0.20% 🔺 295,677 295,901 83,867 84,034

Generated by 🚫 dangerJS against 78cfcfc

docs/static/_redirects Outdated Show resolved Hide resolved
packages/material-ui/src/ButtonBase/ButtonBase.js Outdated Show resolved Hide resolved
packages/material-ui/src/ButtonBase/ButtonBase.js Outdated Show resolved Hide resolved
@@ -89,7 +89,18 @@ class ButtonBase extends React.Component {
});

componentDidMount() {
prepareFocusVisible(this.getButtonNode().ownerDocument);
const button = this.getButtonNode();
if (button == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if the Jest issue is actually solvable or a limitation that can't be solved?

Copy link
Member

@oliviertassinari oliviertassinari May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suspect it's not actionable for the users: #15598 (comment).

Copy link
Member

@oliviertassinari oliviertassinari May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apanizo do you have a reproduction example for the jest snapshot issue? It remembers me: #12247, #5531.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I could create a simple reproduction.

Copy link
Member

@oliviertassinari oliviertassinari May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the beginning of an answer: facebook/react#7740. I see that it's a common problem in the ecosystem: Popmotion/popmotion#736. I'm not sure that we can move forward in this direction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MenuList has the same issue. Probably others as well.

@eps1lon I'm not advocating that we try to have the whole library support react-test-renderer. Menu would have already had this issue in v3, so we aren't likely impacting anyone new there. I am mainly just concerned about ButtonBase being a new place where this is an issue. Just about every page in most apps will have buttons and other things that leverage ButtonBase. I would expect that it is the most-used component.

Copy link
Member

@oliviertassinari oliviertassinari May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryancogswell I think that it's fine to give core contributors a free pass when they feel strongly about something. The recovery cost is cheap with this change. If we really need to change the approach in the future, we can. The advantage of being strict is that we will learn more about our developers use cases. They can always open a new issue about the problem, as well as upvote it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react-test-renderer runs layout effects though which means e.g. a MenuList would crash because focus isn't mocked. I created a small repo to illustrate the issues and I can only come to the conclusion that react-test-renderer is not viable for our components. I couldn't get it to work for Modal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: tests already crash in codesandbox when importing our components. We should also investigate that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with that. I just think this would have been something that would have been nice for users to have longer warning about from a migration standpoint. I agree that it will be useful to know how many people really have a problem with this and how painful it will or won't be for them to address.

@eps1lon eps1lon force-pushed the feat/ButtonBase/improve-component-warning branch from 112fe23 to 57cff46 Compare May 8, 2019 14:33
@eps1lon eps1lon force-pushed the feat/ButtonBase/improve-component-warning branch from 57cff46 to 92d984b Compare May 8, 2019 17:06
@oliviertassinari
Copy link
Member

oliviertassinari commented May 8, 2019

The GitHub out of order message problem makes it hard to follow the conversation. I'm proposing the following plan of action:

  1. In this pull request, we add a defensive check to fallback to document if this.getButtonNode() is null. No error, no warning. It's the pragmatic approach, few people will render their app outside the default document.
  2. During the classes to hooks migration, we introduce the error back in a React.useEffect().

@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label May 8, 2019
@ryancogswell
Copy link
Contributor

The GitHub out of order message problem makes it hard to follow the conversation.

I found it very interesting earlier today to see the two of you making comments in the future (e.g. oliviertassinari commented 4 hours from now). Apparently, the issue was related to bad handling of time zones.

@eps1lon eps1lon merged commit 7805e7c into mui:next May 9, 2019
@eps1lon eps1lon deleted the feat/ButtonBase/improve-component-warning branch May 9, 2019 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: ButtonBase The React component. docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ButtonBase ownerdocument error
5 participants