-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[core] refactor: remove manual displayName
#17845
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
Conversation
Deploy preview: https://deploy-preview-17845--material-ui-x.netlify.app/ |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
I expected this to affect lines like https://github.com/mui/mui-x/blob/master/packages/x-tree-view/src/internals/plugins/useTreeViewItems/useTreeViewItems.test.tsx#L32 But it seems our babel files are not run on vitest. After checking, our babel setup is not compatible with our current test setup, so would require some work to make them work together. @Janpot FYI |
Ah no, that was by design, that's why I initially proposed to do it this way. |
Ah true, in that case we can try running Babel just with specific plugins |
Why were the tests designed to run without the babel plugins? Context: #17903 (comment) |
2025 tooling almost exclusively is being built on top of js parsers and bundlers that work at "native speed". Enabling babel plugins in this kind of tooling is usually possible, but rather as an extra compile step that is significantly slower than the default. If babel is just here to do downleveling of modern js/ts, is it still worth it having to teach all of the tooling to speak babel? The tests weren't specifically designed to work without babel, one of the ideas of moving to vitest was to reduce the reliance on babel so that eventually we can work towards removing this babel.config.js altogether, in favor for a post-production-build step should there be any mui-specific needs left. Leaving our source code maximally portable between engines and compilers as to make it easy to introduce and tweak tooling without every time imposing a slowdown. And as we've noticed building the css support in X, babel as a build tool itself falls short for its purpose here. It's a 1-to-1 file transformation, but to do properly what you want it to do you need bundling capabilities. Where exists the notion of a module graph, and where is lots of control over the whole build lifecycle. Keeping the reliance on babel solely for downleveling purposes keeps the migration path easy to the next version of of our build pipeline. After core is on vitest, we likely want to explore moving to a build tool like vite, tanstack/config, or tsup to build our libraries. For better performance, and to be able to tap in to the rollup ecosystem for things like the css support. So in the context of that mindset, the display name plugin may be a slight step backwards as it forces us to add a babel transform to the tests again potentially slowing it down. We all make different trade-offs though, the above has been discussed a bit before in code-infra, but not extensively. I'd love to hear more perspectives. About the displayName plugin, should we decide it's not substantial enough DX improvement to trade-in performance of our tooling, I do have an alternative: which is to put it back in the sources, but write an eslint plugin that can enforce it. It could be great DX if there's an autofix in the plugin as that would free us from having to write those manually. It also has the added benefit of leaving an easy way to override should we have specific cases where we want to do something different. |
Another small note, some of the native tools aren't mature enough yet, see these issues for SWC vs Babel. Feels like the early days of GCC vs Clang. Clang wins eventually, but it needs enough time to catch up. |
Agreed, downleveling and optimization. The point is, anything that bundlers and runtimes are incentivezed to adopt natively. What doesn't fall under that umbrella is anything that alters the semantics of the language. e.g. we removed babel macros because it just turns your code in something that only babel can run. Portability is important here. And that's mostly important because I want the code to be accessible to newcomers. The only thing you should need to consult to understand the semantics of the code is the ECMA standard, the typescript docs.
Sure, but it's only one tool that is slower, instead of all tools. And if we ever want to switch to another tool, it's only one other tool to port plugins to, instead of all. We're also already running eslint, we already pay the cost. An extra plugin doesn't add much to this cost. Most of us run eslint on save, so it also just has to run on a single file at once most of the time.
Fully agreed, that's why I think we should be very strict about whether plugins can change semantics or not. So that readers don't need to know more than standard javascript (tyescript) when they read our code. Granted, the display name plugin rides the grey zone very well here. On one hand one could argue it changes semantics because it breaks the tests, on the other hand one could argue all it does is adding extra debugging infromation.
I follow you point, but that code is mostly more readable for other reasons than the removal of |
Follow-up of mui/base-ui#1920
Depends on mui/mui-public#329