-
Notifications
You must be signed in to change notification settings - Fork 16
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] Create new Error() minification infrastructure #204
Comments
The method used in core has the best DX, but fully locks us into babel. If we're going to propagate this, can we think of alternatives that still have acceptable DX, but keep the code portable across build tools and runtimes? For example, would it be an acceptable DX to just write it manually throw createMinifiedError(process.env.NODE_ENV === 'production' ? 123 : 'non minified error message', foo, bar) // createMinifiedError
export function createMinifiedError(msg, ...args) {
if (process.env.NODE_ENV === 'production') {
return new Error(format(`minified error #${msg}`, ...args))
}
return new Error(format(msg, ...args))
} (assuming we pair this with a lint rule and an extraction script) |
Maybe a SWC plugin could do this? On the simpler version, I wonder if people will be able to use it reliably. Mistakes potential:
Maybe it's fine. |
It definitely could, but that would:
The idea would be that we still have a script, that uses a babel plugin to extract the messages and update a json file. This script can fail on the cases you mention. We run it locally before pushing and in CI to check for changes. |
I'm changing my mind about this. The problem is the fact that we use Improved DX:
input: throw new Error(`Invalid ${foo} in ${bar}`); Output import formatProdError from '@mui/utils/formatProdError'
// ...
throw new Error(process.env.NODE_ENV !== 'production' ? `Invalid ${foo} in ${bar}` : formatProdError(123, foo, bar)); and ./error-codes.json
{
"123": "Invalid % in %"
}
|
Steps to reproduce
Today, the components throw errors in plain strings:
https://github.com/mui/mui-x/blob/dd4447c5d26e578def9a560df8b2bbda2a3ca317/packages/x-tree-view/src/internals/plugins/useTreeViewItems/useTreeViewItems.tsx#L36-L43
those add bundle size to end-users
Context
We should be able to encode them with a key and only bundle this. See mui/material-ui#21214 for prior art on Material UI.
The text was updated successfully, but these errors were encountered: