mui / mui/base-ui

[utils] Improve warn() / error() utils

Open
#2,589 0 comments 1 reaction 0 assignees View on GitHub
package: utils umbrella
Dominant language
TypeScript
Stars
10.9k
Forks
543
Avg merge
1d 20h
Merged PRs (30d)
101

Description

## Summary

We have two console utils:

https://github.com/mui/base-ui/blob/0f2b7a1e4220a61f496257c7497e926e2b69a03a/packages/utils/src/warn.ts#L6
https://github.com/mui/base-ui/blob/0f2b7a1e4220a61f496257c7497e926e2b69a03a/packages/utils/src/error.ts#L6

I believe we have a couple of issues/opportunities to improve them. I expect them to be used across the codebase, so the details will have a compounding impact, hence this umbrella issue. The list I can see:

- [ ] Add a reset cache util for the tests. See https://github.com/mui/mui-x/blob/e83c26a05fdf625c03c1636d451f0425dd96c9fc/packages/x-internals/src/warning/warning.ts#L32 as an example.
- [ ] Enforce production pruning: https://github.com/mui/mui-public/issues/207
- [ ] Rename the method to be clear. There are cases where we might need to warn/error each time the method is called, but it's not how this behaves, so I believe `warn()` is confusing; it should be `warnOnce()` to be clear.
- [ ] The component stacks do not show up, even when the React DevTools is attached: https://github.com/facebook/react/issues/28992#issuecomment-2485403001. If it doesn't get fixed, it feels like we have to add `captureOwnerStack()`. https://react.dev/reference/react/captureOwnerStack. For example, finding the origin of the console was so painful in https://github.com/mui/material-ui/pull/46804.
- [ ] Migrate the Joy UI, Material UI, MUI X codebase to adopt it.
- [ ] Support arrays for multiple formatting clarity. Example: https://github.com/mui/mui-x/blob/e83c26a05fdf625c03c1636d451f0425dd96c9fc/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx#L81

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.