-
-
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
[docs] Add ref forwarding to API docs #15135
Conversation
2a564bf
to
51133c0
Compare
No bundle size changes comparing ae24eea...27fd460 |
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.
Should the ref always be forwarded to the root element?
What about writing it down on all the documentation pages? This way, we will get bug issue reports on the components that don't follow it. Issue reports we can fix.
51133c0
to
cd7612d
Compare
@@ -273,6 +273,10 @@ function generateProps(reactAPI) { | |||
return textProps; | |||
}, text); | |||
|
|||
text = `${text}\nThe \`ref\` is ${ | |||
reactAPI.forwardsRefTo == null ? '**not** ' : '' | |||
}forwarded to the root element.\n`; |
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.
We probably need more granular control of this. I'm not sure this is always the "root element" (in any definition proposed in #15138).
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.
We have one case where it's not the case <ListItem button />
. We might have another one with InputBase.
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.
ListItem
is actually a component where I would consider the current behavior a bug. But it's a component that is good example where "root = outermost" definition breaks.
InputBase
looks good to me.
We can improve the test for this behavior with one of your suggestions from #15138 (comment)
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.
InputBase looks good to me.
I mean, if we move #14580 forward.
cd7612d
to
d5d458a
Compare
@@ -273,6 +273,14 @@ function generateProps(reactAPI) { | |||
return textProps; | |||
}, text); | |||
|
|||
let refHint = 'The `ref` is forwarded to the root element.'; | |||
if (reactAPI.forwardsRefTo == null) { | |||
refHint = 'The component cannot hold a ref.'; |
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 is the case for almost all components that do not forward refs. Even if some of them can hold a ref we want to prevent users from doing that because converting those components to function components would be breaking.
if (reactAPI.forwardsRefTo == null) { | ||
refHint = 'The component cannot hold a ref.'; | ||
} else if (reactAPI.forwardsRefTo === 'React.Component') { | ||
refHint = 'The `ref` is attached to a component class.'; |
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.
TouchRipple is the only candidate for that (allows imperative handle). The other components will be covered by #15170.
df0fd00
to
27fd460
Compare
This should be addressed now. Every API page has a hint about ref forwarding. There are currently 3 different hints:
For components that will be converted function components. It's easier to go from "no ref" to "some ref" instead of "class instance ref" to "host ref"
E.g. TouchRipple |
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 have no strong point of view on this topic. I'm happy to trust your call here.
@@ -199,7 +204,11 @@ function run() { | |||
const components = findComponents(path.resolve(rootDirectory, args[2])); | |||
|
|||
components.forEach(component => { | |||
buildDocs({ component, pagesMarkdown }); | |||
buildDocs({ component, pagesMarkdown }).catch(error => { |
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 surprised it hasn't exploded yet 🚀🌕. This is like 200 concurrent promises 💪.
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 will celebrate the day uncaught promises will just throw. The current state of async errors in node is really annoying.
Adds explicit documentation to
https://material-ui.com/api/*
about ref forwarding. Requires #15131 to not report false positives.Finishes one point in #14415.