Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[material-ui] Fix Accessing element.ref #42818
[material-ui] Fix Accessing element.ref #42818
Changes from 10 commits
3ecc332
916c3a5
9ee9592
117305f
e781158
a8e9190
ec910e5
1d5f95d
7fa5eda
2f926cd
5bc21fa
916818e
95a319b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This feels wrong. The prop type is already here to validate this constraint, but without bundle size or runtime overhead in production.
I could see value if it means a clearer failure mode, it gives us a single clear console log or exception thrown, but not sure it's what we do here.
As for React 19 not supporting prop types anymore, I still pretty convinced that we need to bring in an equivalent support where TypeScript is unable to cover the same constraints.
At the very least, the last segment is unreachable, no?
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.
fair, since components using
getChildRef
handling this, we might not need checking count here. removed -> 916818eThere 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.
@sai6855 I don't think it's about where
getChildRef
is called.If
React.isValidElement(children)
is false, then it return null.If
React.isValidElement(children)
is true, then it checkReact.Children.count(children)
but it will always return 1 since it's children is a valid element.So
|| React.Children.count(children) !== 1
always wastes CPU/network work, so it should be removed.Now, on the use of
|| !React.isValidElement()
, I think that it really depends on the DX we want to provide.If we want to keep the same DX tradeoff as before, we should remove it, it slows the runtime with nothing in exchange.
If we want to make it so that even if developers can render a component without a children, get a console.error, type error not no exception that developers could be deceived by, then we could either decide to keep it, or probably better, to add a
if (process.env.NODE_ENV !== 'production' && React.isValidElement(children)) { return null }
in the render body of the function. In which case we should also remove it.So I conclude that great looks like this:
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.
thanks for detailed explaintation, opened PR to refactor -> #43022
TL,DR; of PR is