Skip to content
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

[utils] Add all @material-ui/core/utils to @material-ui/utils #23264

Merged
merged 35 commits into from
Oct 28, 2020

Conversation

mnajdova
Copy link
Member

This PR prepares unnecessary changes for introducing the @material-ui/unstyled package. It moves the @material-ui/core/utils utilities to @material-ui/utils, so that those can be reused in the new package. All previous @material-ui/core/utils are now just re-exporting the @material-ui/utils

@mui-pr-bot
Copy link

mui-pr-bot commented Oct 26, 2020

@material-ui/utils: parsed: +71.54% , gzip: +65.22%

Details of bundle changes

Generated by 🚫 dangerJS against 1312f19

@@ -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';
Copy link
Member Author

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

Copy link
Member

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?

@mnajdova mnajdova requested a review from eps1lon October 26, 2020 10:18
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';
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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

  1. bumping the major version number of the package
  2. bumping the pre-release number if it's an alpha
  3. do nothing (but documentation) if it's prefixed as unstable_
    unstable_ is still only an informal convention so we should still be careful.

Copy link
Member

@oliviertassinari oliviertassinari Oct 27, 2020

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 👍.

Copy link
Member Author

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

Copy link
Member Author

@mnajdova mnajdova Oct 27, 2020

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_

Copy link
Member

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?

Copy link
Member Author

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.

@oliviertassinari oliviertassinari added the core Infrastructure work going on behind the scenes label Oct 26, 2020
packages/material-ui-utils/src/capitalize.ts Outdated Show resolved Hide resolved
}
import { ownerDocument } from '@material-ui/utils';

export default ownerDocument;
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

@oliviertassinari oliviertassinari left a 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.

@mnajdova mnajdova dismissed eps1lon’s stale review October 27, 2020 18:30

Issue with the macro was resolved

import * as React from 'react';

/**
* Private module reserved for @material-ui packages.
Copy link
Member

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.

Copy link
Member

@oliviertassinari oliviertassinari Oct 28, 2020

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/unstyled depends on @material-ui/internal
  • @material-ui/system depends on @material-ui/internal
  • @material-ui/styles depends on @material-ui/internal
  • @material-ui/unstyled reexport some of the utils we want to make public
  • @material-ui/core reexport some of the utils we want to make public, from @material-ui/unstyled
  • @material-ui/internal is versioned as alpha so we can make BCs

Copy link
Member

@oliviertassinari oliviertassinari Oct 28, 2020

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:

https://github.com/mui-org/material-ui/blob/0aefc928b00788b0ec5f74842b7c9704a354cf4a/docs/src/pages/components/breadcrumbs/RouterBreadcrumbs.tsx#L15

do we still need it with the new versions of TypeScript?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@oliviertassinari oliviertassinari Oct 28, 2020

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).

Copy link
Member

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.

Copy link
Member

@oliviertassinari oliviertassinari Oct 28, 2020

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.

Copy link
Member

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.

Copy link
Member

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.

@eps1lon
Copy link
Member

eps1lon commented Oct 28, 2020

Also: can we make the TS migration in another PR? We now have .d.ts files alongside .ts files and some .ts files just have a big @ts-ignore making it meaningless that they're written in .ts.

@mnajdova
Copy link
Member Author

Also: can we make the TS migration in another PR? We now have .d.ts files alongside .ts files and some .ts files just have a big @ts-ignore making it meaningless that they're written in .ts.

You mean to move the same .js & d.ts files we had before from the @material-ui/utils package?

@mnajdova
Copy link
Member Author

Also: can we make the TS migration in another PR? We now have .d.ts files alongside .ts files and some .ts files just have a big @ts-ignore making it meaningless that they're written in .ts.

That will probably mean we need to change the build of that package, because as far as I remember it was ts module before.

@eps1lon
Copy link
Member

eps1lon commented Oct 28, 2020

You mean to move the same .js & d.ts files we had before from the @material-ui/utils package?

I thought we move from /core/utils to /utils so I meant keep the files as-is from /core/utils.

@mnajdova
Copy link
Member Author

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 scrollLeft.js, which is added in this PR, all other files are moved as is.

@mnajdova mnajdova requested a review from eps1lon October 28, 2020 11:53
Copy link
Member

@mbrookes mbrookes left a 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/src/capitalize.js Outdated Show resolved Hide resolved
packages/material-ui-utils/src/capitalize.js Outdated Show resolved Hide resolved
packages/material-ui-utils/src/useIsFocusVisible.js Outdated Show resolved Hide resolved
packages/material-ui-utils/src/useIsFocusVisible.js Outdated Show resolved Hide resolved
packages/material-ui-utils/src/useIsFocusVisible.js Outdated Show resolved Hide resolved
packages/material-ui-utils/src/isMuiElement.d.ts Outdated Show resolved Hide resolved
packages/material-ui-utils/src/useId.js Outdated Show resolved Hide resolved
mnajdova and others added 22 commits October 28, 2020 19:20
…/error-codes.json

Co-authored-by: Matt <github@nospam.33m.co>
…/input.js

Co-authored-by: Matt <github@nospam.33m.co>
…/output.js

Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
@mnajdova mnajdova merged commit 03bd73b into mui:next Oct 28, 2020
let timeout;
function debounced(...args) {
const later = () => {
func.apply(this, args);

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants