Skip to content

[code-infra] Avoid loading barrel file during type checking #46177

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

Merged
merged 5 commits into from
May 19, 2025

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented May 19, 2025

Noticed during type checking of the following:

import * as React from 'react';
import Button from '@mui/material/Button';

export default function Test() {
  return <Button>hello</Button>;
}

That it loaded the whole type declarations for @mui/material top-level barrel file:

Screenshot 2025-05-19 at 08 41 34

I saw there were lots of imports from '..' in the individual subpaths. This is wasteful, better to import more deeply.

-import { Theme } from '..';
+import { Theme } from '../styles';

after:

Screenshot 2025-05-19 at 08 41 43

You can see there's still a large chunk being loaded for them, it still imports all component props for the theme. But it's already about 30% faster (according to those two traces, I didn't sample multiple runs).

  • Will look into whether this theme declaration file can be further optimized.
  • Will also investigate in follow-up whether we can enforce this with eslint.

@Janpot Janpot added the scope: code-infra Specific to the core-infra product label May 19, 2025
@mui-bot
Copy link

mui-bot commented May 19, 2025

Netlify deploy preview

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

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against b58d10e

@Janpot Janpot marked this pull request as ready for review May 19, 2025 07:28
@Janpot Janpot requested review from DiegoAndai and a team May 19, 2025 07:29
Copy link
Member

@JCQuintas JCQuintas left a comment

Choose a reason for hiding this comment

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

I suppose these imports can be caused by some IDE configs, would there be an eslint rule so we can block these? 🤔

@Janpot
Copy link
Member Author

Janpot commented May 19, 2025

I moved the internal type to @mui/material/internal

I suppose these imports can be caused by some IDE configs, would there be an eslint rule so we can block these? 🤔

Quite hard to do with eslint-plugin-imports, but I'm adding a custom plugin in a separate PR

@Janpot Janpot merged commit 9c6871d into mui:master May 19, 2025
20 checks passed
@sai6855
Copy link
Contributor

sai6855 commented May 19, 2025

test-types CI check is failing after merging latest master in this PR #45975, looks like this PR might be causing the issue although not entirely sure. https://circleci.com/gh/mui/material-ui/827381

Edit: Issue might be in PR itself

@Janpot
Copy link
Member Author

Janpot commented May 19, 2025

Edit: Issue might be in PR itself

👍 Ok, let me know.

Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

Thanks @Janpot

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.

5 participants