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

[code-infra] Inject display name #44067

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented Oct 11, 2024

Implements mui/mui-public#209 to stabilise tests and improve DX

  • Adjust proptypes script to also inject a displayName
  • Add babel plugin to remove displayName in production

Individual commits for easier review:

@Janpot Janpot added the scope: code-infra Specific to the core-infra product label Oct 11, 2024
@mui-bot
Copy link

mui-bot commented Oct 11, 2024

Netlify deploy preview

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

@material-ui/core: parsed: +0.18% , gzip: +0.13%
@mui/joy: parsed: +0.12% , gzip: +0.08%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against d0934c0

@@ -167,4 +167,6 @@ Button.propTypes /* remove-proptypes */ = {
to: PropTypes.string,
} as any;

Button.displayName = 'Button';
Copy link
Member

Choose a reason for hiding this comment

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

What about?

Suggested change
Button.displayName = 'Button';
if(process.env.NODE_ENV !== 'production') {
Button.displayName = 'Button';
}

this would mean:

  1. be sure there is no regressions
  2. give developers developer confidence that this isn't going to bloat their bundle
  3. In the code ejection story, we could automatically wrap this, but I would expect people to also copy and paste the source too

Copy link
Member Author

@Janpot Janpot Oct 12, 2024

Choose a reason for hiding this comment

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

I thought about it but went for the current solution because

  • Parity with the proptypes generation. Both work the exact same way: upsert code => wrap in build step. If you understand one, you also understand the other. If we add in the conditional for displayName, then I think we should do the same for propTypes and remove the babel plugin.
  • It's more straightforward and robust for the detection logic if it consists of a single top-level statement statement.
  • It prevents people from getting tempted adding more things in the coditional. Which in turn would either break the detection logic, or make it much more complex.

Copy link
Member

Choose a reason for hiding this comment

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

Parity with the proptypes generation

Ah right ok, I forgot, I thought we were doing the opposite. Makes sense then 👍

Janpot and others added 2 commits October 12, 2024 00:32
…opTypesInFile.ts

Co-authored-by: Olivier Tassinari <[email protected]>
Signed-off-by: Jan Potoms <[email protected]>
…opTypesInFile.ts

Co-authored-by: Olivier Tassinari <[email protected]>
Signed-off-by: Jan Potoms <[email protected]>
@JCQuintas
Copy link
Member

Should this be a babel plugin instead? Do we need to commit these changes? 🤔

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: code-infra Specific to the core-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants