-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
[utils] Add all @material-ui/core/utils to @material-ui/utils #23264
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
|
@material-ui/utils: parsed: +71.54% , gzip: +65.22% |
| @@ -0,0 +1,13 @@ | |||
| // TODO: error TS7016: Could not find a declaration file for module '../macros/MuiError.macro'. '/tmp/material-ui/packages/material-ui-utils/macros/MuiError.macro.js' implicitly has an 'any' type. | |||
| // import MuiError from '../macros/MuiError.macro'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eps1lon FYI we have this issue with the macros
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you @ts-expect-error this instead for now so that we don't sacrifice the runtime behavior for typings?
| export { default as requirePropFactory } from './requirePropFactory'; | ||
| export { default as setRef } from './setRef'; | ||
| export { default as unstable_useEnhancedEffect } from './useEnhancedEffect'; | ||
| export { default as unstable_useId } from './useId'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the unstable prefix if we treat all the modules here private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they're here, they're public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot where I said but I would be way more comfortable by renaming /utils to internal or even unsafe_internal. There are already plenty of packages depending on /types and I suspect the same happened with /utils.
Or we release it as an alpha.
Either way, I agree that the current state of /utils being on the same release line as /core (5.x) does not signal that the package is private. It's simply not enough that we treat it as private since we have some responsibility to not clutter npm with more underdocumented packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we then proceed with #23270 move all utils in unstyled and export them as unstable_? Then for avoiding breaking changes, we can reuse them in the core and just reexport them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then for avoiding breaking changes, we can reuse them in the core and just reexport them.
I don't understand what that solves.
If we change the API of useId and only we consume useId then everything is fine.
If useId can also be used by library consumers directly then we can only release a breaking change either by
- bumping the major version number of the package
- bumping the pre-release number if it's an alpha
- do nothing (but documentation) if it's prefixed as
unstable_
unstable_is still only an informal convention so we should still be careful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or should we move them to the new@material-ui/unstyled package and again to export them as unstable_
Considering that some of the utils are required by the system, it would mean the system needs to depend on unstyled. I assume that it's not something we want because the two are solving independent problems.
Should we move all these utils to @material-ui/utils as this PR is doing and export them all as unstable_
I think that this option can work 👍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, let me update the exports then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, everything in @material-ui/utils that comes from @material-ui/core/utils is exported as unstable_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're importing unstable_createFunction from /utils and re-export it as createChainedFunction from /core/utils. I don't know how this is supposed to work: If /utils can change the API of createChainedFunction on every release and /core pins /utils to major then createChainedFunction from /core/utils can also change on every release and is therefore unstable.
What did we try to accomplish by adding (and not moving) /core/utils to /utils?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to make changes to the existing core/utils as we have imports all over the project from there. I started like that in #23203 prepared codemods as well, but we decided to go wtih the minimal changes necessary for unblocking ourselves, which is to move the utils to core, but still re-export them from the core in order to avoid changes in the core.
| } | ||
| import { ownerDocument } from '@material-ui/utils'; | ||
|
|
||
| export default ownerDocument; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we should remove these files. As far as I can tell they're not necessary anymore which means we can safely reduce the number of files we ship.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have local imports in all core components to this files, I am re-exporting to avoid changes in all core files. I've started with that approach here #23203 but there were too many changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Let's keep this conversation open for visibility.
…at-self Add compat for usage in utils itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the direction taken. I think that it's a great compromise.
| import * as React from 'react'; | ||
|
|
||
| /** | ||
| * Private module reserved for @material-ui packages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we resolve what the intent of @material-ui/utils is? This is exported as unstable_ but annotated as private. The current state of @material-ui/utils is a mixed bag that can not be understood reasonably by npm users and it looks like even we don't know what this package is.
We'd do us a big favor if we would just rename it to /internal so we don't have to worry about maintaining utils and then we bump the required version in the dependent packages on every release.
It's not a blocker for this PR but definitely for the next release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eps1lon Agree! Let's try to come up with an answer. You are right unstable mean we plan to make it public while private, well, is private. However, I don't think that we should solve it here. For later.
Maybe the following?
@material-ui/utils->@material-ui/internal@material-ui/types->@material-ui/internal@material-ui/unstyleddepends on@material-ui/internal@material-ui/systemdepends on@material-ui/internal@material-ui/stylesdepends on@material-ui/internal@material-ui/unstyledreexport some of the utils we want to make public@material-ui/corereexport some of the utils we want to make public, from@material-ui/unstyled@material-ui/internalis versioned as alpha so we can make BCs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eps1lon I have noticed @material-ui/types used in the documentation for one use case:
do we still need it with the new versions of TypeScript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need it with the new versions of TypeScript?
We don't need it for new versions of typescript but haven't had any discussions about bumping the required versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reexport some of the utils we want to make public
Then what is the point of moving them into an internal package if we just re-export them? That's not what internal means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven't had any discussions about bumping the required versions.
@eps1lon Do we need a discussion about changing the supported version of TypeScript?
Then what is the point of moving them into an internal package if we just re-export them
Great question, the only value I can think of is to allow @material-ui/system to depend on @material-ui/internal rather than @material-ui/unstyled (also true for @material-ui/styles but the packages it getting deprecated so I don't think that we should optimize for it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a discussion about changing the supported version of TypeScript?
Like any other breaking change: yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like any other breaking change: yes.
Sorry, I wasn't clear. Do we want/need to change the minimum version of TypeScript supported? I'm personally not familiar with the matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't though about it but since we didn't change anything we still need an Omit polyfill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just that we test with the latest version where we don't need it. But 3.2 does which is what we support.
|
Also: can we make the TS migration in another PR? We now have |
You mean to move the same .js & d.ts files we had before from the |
That will probably mean we need to change the build of that package, because as far as I remember it was ts module before. |
I thought we move from /core/utils to /utils so I meant keep the files as-is from /core/utils. |
Done, the only thing missing was a definition file for |
mbrookes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just a bunch of trivial changes to internal comments
packages/material-ui-utils/macros/__fixtures__/relative-import/error-codes.json
Outdated
Show resolved
Hide resolved
packages/material-ui-utils/macros/__fixtures__/relative-import/input.js
Outdated
Show resolved
Hide resolved
packages/material-ui-utils/macros/__fixtures__/relative-import/output.js
Outdated
Show resolved
Hide resolved
…/error-codes.json Co-authored-by: Matt <[email protected]>
…/input.js Co-authored-by: Matt <[email protected]>
…/output.js Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
| let timeout; | ||
| function debounced(...args) { | ||
| const later = () => { | ||
| func.apply(this, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we do not timeout = undefined here? AFAICT, the setTimeout return value is a number in browsers, and these could be recycled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to submit a PR if this makes sense.
This PR prepares unnecessary changes for introducing the
@material-ui/unstyledpackage. It moves the@material-ui/core/utilsutilities to@material-ui/utils, so that those can be reused in the new package. All previous@material-ui/core/utilsare now just re-exporting the@material-ui/utils