-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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 ownerdocument error #15598
Comments
Please fill out the issue template. We will need more information to look at this. |
Here is the problem, in beta1 you quit the helper for get the owner document and right now if is null get the node get an error obiusly
|
@joacub I believe you are using the - <ButtonBase component={(props) => <a {...props} />}>
+ <ButtonBase component={React.forwardRef((props, ref) => <a ref={ref} {...props} />)}> Docs |
Yeah you are right I’m using the component prop, and is running right before this new version I catch |
@joacub It would be helpful to see the code of the component you are specifying via the
but this is rather odd usage. It would be helpful to see what your exact scenario is so that the appropriate resolution can be determined. |
@ryancogswell the issue is becouse the prop component not is with React.forwardRef and the component not have the ref , my fault becouse the new code change |
yes, if the return is nulled or function or fragment get an error |
Should we introduce a new warning to handle this edge case or ignore it as unlikely to affect many people? @joacub Do you have a minimal reproduction code example to share? |
I am facing this issue without using I am wondering if I am missing something because this should be a pretty common scenario, not an edge case. If I rollback dependencies to
And the script executed is: What do you guys think? |
Issue was likely introduced by #15484. |
The null example is valid I have same code |
I'm experiencing this problem as well with a |
@eps1lon Do you think the following is what we want? diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.js b/packages/material-ui/src/ButtonBase/ButtonBase.js
index 8486c972df6..44c96ba32db 100644
--- a/packages/material-ui/src/ButtonBase/ButtonBase.js
+++ b/packages/material-ui/src/ButtonBase/ButtonBase.js
@@ -112,7 +112,10 @@ class ButtonBase extends React.Component {
}
getButtonNode() {
- return ReactDOM.findDOMNode(this.buttonRef.current);
+ if (this.buttonRef.current) {
+ return ReactDOM.findDOMNode(this.buttonRef.current);
+ }
+ return ReactDOM.findDOMNode(this);
}
onRippleRef = node => { |
@ryancogswell We will soon move the ButtonBase from the classes to the hooks. We can't rely on
|
@oliviertassinari Are you planning to still do this yet in v4? This seems like a pretty big breaking change to not yet have in the beta. |
It seems like this issue is caused for two reasons:
|
Using the documented react-router integration works, thanks. As it's a BC break compared to v3, I'd expect that information to appear in the upgrade guide - otherwise, it's really hard to find. |
Do you have a reproduction? There should be a warning in your console linking to an upgrade path. |
The reproduction is But from your question, I'm understanding that you consider that a warning in the console replaces a mention in the Upgrade guide, am I right? If so, let me express my preference for a mention in the upgrade guide, which lets me fix the problem before users encounter it in production. |
@eps1lon What do you think of a note like this regarding the forwardRef https://next.material-ui.com/guides/migration-v3/#dialog? |
The migration notes are just incomplete. It's missing the forwardRef requirement from the findDOMNode changes. It just has to link to https://next.material-ui.com/guides/composition/#caveat-with-refs which has extensive information about the change. |
I just upgraded to the latest @next today and started to experience this issue. Before finding this github issue, I bisected the commits and have pinned the error down to this commit #15484 Before I upgraded to the latest @next I was using the following, which seems to be the suggested fix?
I tried changing it to:
Same error. Since it seems I'm already doing what is suggested above, I don't think this is the correct fix. Am I missing something? |
@bretep Could you isolate the issue in a codesandbox? Without knowing where NavLink (implementation, package, version etc) I can't really help you. |
Working on it now. Are you guys in any chat channel or just github issues? |
@eps1lon My browser was on the wrong route and did not hit the new code path. 😔 Summary From:
To:
|
For anybody having this issue with // test utils
function createNodeMock() {
return {
nodeType: 1, // to trick findDOMNode
// for focus-visible polyfill
ownerDocument: {
addEventListener: () => {},
removeEventListener: () => {}
},
};
}
// test
it("can mount a button", () => {
const renderer = TestRenderer.create(<Button>test</Button>, {
createNodeMock
});
expect(renderer.toJSON()).toMatchSnapshot();
}); Though it is very likely that you encounter issues with other components as well since we still have a dependency on the DOM. Though I encourage everyone to use as little snapshot tests as possible I will work on a more extensive |
To help others searching, this can also show up as "Error: Material-UI: expected an Element but found null" in ButtonBase.componentDidMount. The createNodeMock above solves this. (Perhaps it would be helpful to add info about mocking to that error message when running in a test environment?) For people using Storybook snapshots, createNodeMock is a Storyshots init option. |
This issue will be fixed incidentally when converting ButtonBase to a function component. Preparation of the focus visible polyfill will happen in the ref phase. In that phase we have to guard against I'm currently in the state where I think that any reading of It's not ideal since it might hide an a11y issue but we it will already log 2 warnings so I guess this is ok.
Sounds like a good idea to add this to https://next.material-ui.com/. Basically explaining that we have a dependency on the DOM and that you should mock this accordingly. |
Expected Behavior 🤔
Current Behavior 😯
Steps to Reproduce 🕹
Link:
Context 🔦
Your Environment 🌎
Error getting ownerdocument when component is different to the default
The text was updated successfully, but these errors were encountered: