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

[core] Handle refType in the proptypes generation #38917

Closed
wants to merge 1 commit into from

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Sep 11, 2023

@flaviendelangle flaviendelangle added the core Infrastructure work going on behind the scenes label Sep 11, 2023
@flaviendelangle flaviendelangle self-assigned this Sep 11, 2023
@mui-bot
Copy link

mui-bot commented Sep 11, 2023

Netlify deploy preview

https://deploy-preview-38917--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 1a292d8

@flaviendelangle flaviendelangle force-pushed the refType branch 2 times, most recently from f9b8721 to fd79bd4 Compare September 11, 2023 10:44
const usedCustomValidator =
previous !== undefined &&
!previous.startsWith('PropTypes') &&
!previous.startsWith('refType');
Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer to move this logic inside TTP to share it with X.
For now, if we forget to copy paste on X, we have diverging before for no reason.

@flaviendelangle flaviendelangle changed the title [core] Handle refType in the proptypes generation [core] Handle refType in the proptypes generation Sep 11, 2023
"description": "func<br>&#124;&nbsp;{ current?: { focusVisible: func } }"
}
},
"action": { "type": { "name": "custom", "description": "ref" } },
Copy link
Member Author

Choose a reason for hiding this comment

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

@oliviertassinari for these custom refs, it might be debatable if the new generation is actually better.

I'd say that func | { current?: { focusVisible: func } } was not very readable anyway, but still we are loosing information.

I can avoid using refType when the ref value is not an HTML element.

Copy link
Member Author

Choose a reason for hiding this comment

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

Of change refType to have refDOMNodeType for the HTML elements and refType(...) that takes a param for the custom refs

actions: refType({
  focusVisible: PropTypes.func,
})

Copy link
Member

@oliviertassinari oliviertassinari Sep 11, 2023

Choose a reason for hiding this comment

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

Agree, I think a ref implies access to a DOM node, which isn't the case here.

https://mui.com/base-ui/react-tabs/components-api/#Tab-prop-action feels better than: https://deploy-preview-38917--material-ui.netlify.app/base-ui/react-tabs/components-api/#Tab-prop-action.


It feels like we are hitting a limit of TypeScript → prop-types → docs. It should really be:

  • TypeScript → prop-types
  • TypeScript → docs

This feels better than these two: https://deploy-preview-38917--material-ui.netlify.app/base-ui/react-tabs/hooks-api/#prop-rootRef

Copy link
Member Author

Choose a reason for hiding this comment

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

It feels like we are hitting a limit of TypeScript → prop-types → docs. It should really be:

That's the main goal of my architectural changes.
I created a layer that only analyses the AST trees and that should be usable by both and let both add the specificity they want.

@@ -97,14 +98,7 @@ Button.propTypes /* remove-proptypes */ = {
/**
* A ref for imperative actions. It currently only supports `focusVisible()` action.
*/
action: PropTypes.oneOfType([
Copy link
Member

Choose a reason for hiding this comment

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

Off-topic

Maybe for API consistency?

Suggested change
action: PropTypes.oneOfType([
actionRef: PropTypes.oneOfType([

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's an improvement - we lost information about the shape of the ref here. The refType should apply only to refs to HTML elements IMO.

As a side note, if I remember correctly, we're using action props to support focusVisible action, which I'd like to drop around v6 (browser support should be sufficient then).
In other cases (like menus, select, etc.) we expose the dispatch prop that accepts a function instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

#38917 (comment)

I think the right discussion is here

I think we can close the PR
I did a proposal that could be better than the current state, but I don't think the effort is worth it for now

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 9, 2024
@michaldudak
Copy link
Member

Closing per #38917 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants