-
-
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
[styles] Improve ref forwarding #13676
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,10 +83,10 @@ const withStyles = (stylesOrCreator, options = {}) => Component => { | |
return null; | ||
} | ||
|
||
return new Error( | ||
'Material-UI: The `innerRef` prop is deprecated and will be removed in v5. ' + | ||
'Refs are now automatically forwarded to the inner component.', | ||
); | ||
// return new Error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's raising a warning as the ButtonBase is still using this API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I think I annotated it with |
||
// 'Material-UI: The `innerRef` prop is deprecated and will be removed in v5. ' + | ||
// 'Refs are now automatically forwarded to the inner component.', | ||
// ); | ||
}), | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,9 +51,9 @@ describe('withStyles', () => { | |
|
||
const ref = React.createRef(); | ||
mount( | ||
<> | ||
<React.Fragment> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should we do with the Fragment. Should we embrace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
<StyledTarget ref={ref} /> | ||
</>, | ||
</React.Fragment>, | ||
); | ||
assert.instanceOf(ref.current, TargetComponent); | ||
}); | ||
|
@@ -66,39 +66,39 @@ describe('withStyles', () => { | |
|
||
const ref = React.createRef(); | ||
mount( | ||
<> | ||
<React.Fragment> | ||
<StyledTarget ref={ref} /> | ||
</>, | ||
</React.Fragment>, | ||
); | ||
assert.strictEqual(ref.current.nodeName, 'DIV'); | ||
}); | ||
|
||
describe('innerRef', () => { | ||
beforeEach(() => { | ||
consoleErrorMock.spy(); | ||
}); | ||
|
||
afterEach(() => { | ||
consoleErrorMock.reset(); | ||
PropTypes.resetWarningCache(); | ||
}); | ||
|
||
it('is deprecated', () => { | ||
const ThemedDiv = withStyles({})('div'); | ||
|
||
mount( | ||
<> | ||
<ThemedDiv innerRef={React.createRef()} /> | ||
</>, | ||
); | ||
|
||
assert.strictEqual(consoleErrorMock.callCount(), 1); | ||
assert.include( | ||
consoleErrorMock.args()[0][0], | ||
'Warning: Failed prop type: Material-UI: The `innerRef` prop is deprecated', | ||
); | ||
}); | ||
}); | ||
// describe('innerRef', () => { | ||
// beforeEach(() => { | ||
// consoleErrorMock.spy(); | ||
// }); | ||
|
||
// afterEach(() => { | ||
// consoleErrorMock.reset(); | ||
// PropTypes.resetWarningCache(); | ||
// }); | ||
|
||
// it('is deprecated', () => { | ||
// const ThemedDiv = withStyles({})('div'); | ||
|
||
// mount( | ||
// <React.Fragment> | ||
// <ThemedDiv innerRef={React.createRef()} /> | ||
// </React.Fragment>, | ||
// ); | ||
|
||
// assert.strictEqual(consoleErrorMock.callCount(), 1); | ||
// assert.include( | ||
// consoleErrorMock.args()[0][0], | ||
// 'Warning: Failed prop type: Material-UI: The `innerRef` prop is deprecated', | ||
// ); | ||
// }); | ||
// }); | ||
}); | ||
|
||
it('should forward the properties', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm removing all the istanbul ignore, @eps1lon is right, let's leave the 100% utopia.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair that broken window analogy you linked made total sense to me. I just think that these comments won't help in that regard. At least this way we have the actual number to look at. Previously it was 100% (kind of; who knows how good it is actually). Now we know how good/bad we are and have tools helping us analyze it. Codesearch is not really that helpful IMO. It's like prefering
// TODO
over creating issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.