-
Notifications
You must be signed in to change notification settings - Fork 28
[code-infra] Add context to plugin-transform-react-constant-elements #646
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
Bundle size report
|
aaa9ece to
c33a0db
Compare
It's hard call that a win, JSX code in .js files has been giving me a headache for years 😄 All joking aside, if .jsx extension is not allowed, then we should express that in a single place only, a eslint rule. All other tooling should be built to operate on all valid javascript files, inlcuding .jsx files. That gives us maximum freedom to change our mind some day. |
@Janpot The thought is that in the past we didn't use it, and in the future, we are migrating everything to TypeScript, so there seems to there should be no reason to have one .jsx file. So it looks like we can simplify our infra by not having to support it. In practice, the ones I see in https://github.com/search?q=org%3Amui+path%3A*.jsx&type=code&p=1 seems to be about the need to support I reverted this part; it's too far from the main goal of the PR.
Would this fix it https://x.com/kentcdodds/status/1362418720623054848 (we never use |
Signed-off-by: Olivier Tassinari <[email protected]>
2dc4e0a to
5cf1249
Compare
I'm arguing that building all of our tooling for any file that can potentially contain javascript is the simplest solution. Otherwise we have this "no .jsx" rule, that has no-one expects as nobody does this in their project, lingering in all of our tooling.
Somewhat yes, at the moment not all of our // valid in a .ts file, invalid in a .tsx file:
const x = <T>(t: T) => null;What he describes is only a small nuisance though for me. I don't think it would be helpful to be absolutist about this. In a React project it makes sense to say "we write .tsx only", but again that should be a single lint rule that enforces that, all other rules should just operate on any typescript file. Why? because not all of our projects are react projects. And some day there may be a valid need to relax this rule a bit for some files in a React project (e.g. next.config.ts). I believe the biggest tech debt at the moment, after the |
@Janpot Right, to work, it would need an eslint rule that lints all files that can contain JavaScript and asks to use the only valid file extensions.
There are only really a few problems that I see collapsing down the number of extensions to a single
The vibe being: "Why is one not more than enough, can't we delete this complexity"
Right, it's not the biggest priority to fix this, agree. I was thinking more of setting an end goal, so our journey is guided by it.
This one feels unclear: to what I recall, we used to let TypeScript generate the .d.ts files; the generation wasn't perfect, so we moved to manual .d.ts files alongside source (today .tsx). |
Yes, there isn't enough type information in js and the jsdoc types on their own aren't powerful enough to emulate all ts features. That's why there was opted for writing .d.ts files manually. Instead of running So instead of // foo.d.ts
export function foo(a: string): number;
// foo.js
export function (a) {
return Number(a)
}I believe a better way would have been to // types.ts
export type ComplexFunction = (a: string): number;
// foo.js
/** @type {import('./types').ComplexFunction} */
export function (a) {
return Number(a)
}that way we could have kept the whole compilation in |
|
@Janpot Right, I think I got the history wrong:
So it feels like years of slow incremental progress toward the correct approach, it kind of worked, so we never prioritized to fully clean it up 😁
Right, this sounds better. But to also mind that with the .d.ts > propTypes migration, eslint proptypes validation gave us some level of sync guarantee. It's probably how we manage to get away with the problem.
Right mui/material-ui#15984. |
Since we can't git blame in mui-public what's copied from material-ui, I'm adding a comment. I guess from #644 we would fully lose the ability to git diff.
Also side wins:
.tsfile can't have JSXand the..jsxextension is not allowed