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

[theme] Convert transitions from object to ES module #22517

Merged
merged 3 commits into from
Sep 7, 2020

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Sep 6, 2020

View diff without whitespace changes advised.

We're currently exporting an object (namespace) from core/styles/transitions instead of a proper ES module. This means that mutating theme.transitions has global side-effects. We could freeze the object to catch these but we might as well switch to proper ES modules.

@eps1lon eps1lon added the package: material-ui Specific to @mui/material label Sep 6, 2020
@@ -6,7 +6,7 @@ export { default as createStyles } from './createStyles';
export { default as makeStyles } from './makeStyles';
export { default as responsiveFontSizes } from './responsiveFontSizes';
export { default as styled } from './styled';
export * from './transitions';
export { duration, easing } from './transitions';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exports the same methods as before but needed to change since create and getAutoHightDuration are now also named exports in transitions

@@ -17,18 +17,6 @@ export interface Duration {
}
export const duration: Duration;

export function formatMs(milliseconds: number): string;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never exported

// export type TransitionsOptions = DeepPartial<Transitions>;

declare const transitions: Transitions;
export default transitions;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default export is gone but was never part of the public interface (only first and second level imports are public).

@eps1lon eps1lon force-pushed the fix/transitions-module branch from e73a956 to 32c5335 Compare September 6, 2020 10:49
@mui-pr-bot
Copy link

mui-pr-bot commented Sep 6, 2020

Details of bundle changes

Generated by 🚫 dangerJS against 5d0776e

@eps1lon eps1lon changed the title [core] Convert transitions from namespace to ES module [core] Convert transitions from object to ES module Sep 6, 2020
@eps1lon eps1lon marked this pull request as ready for review September 6, 2020 11:54
@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 6, 2020

mutating theme.transitions has global side-effects.

Bug confirmed in https://next.material-ui.com/ with

Capture d’écran 2020-09-06 à 13 59 15

Note that it also impacts zIndex, shadows, and shape.

we might as well switch to proper ES modules

Why going down this road, the module is private? Would it be simpler with?

diff --git a/packages/material-ui/src/styles/createMuiTheme.js b/packages/material-ui/src/styles/createMuiTheme.js
index 9904bff8b5..89cde86d74 100644
--- a/packages/material-ui/src/styles/createMuiTheme.js
+++ b/packages/material-ui/src/styles/createMuiTheme.js
@@ -33,9 +33,9 @@ function createMuiTheme(options = {}, ...args) {
-      shadows,
+      shadows: [...shadows],
       typography: createTypography(palette, typographyInput),
       spacing,
-      shape,
-      transitions,
-      zIndex,
+      shape: { ...shape },
+      transitions: { ...transitions },
+      zIndex: { ...zIndex },
     },
     other,
   );

@oliviertassinari oliviertassinari changed the title [core] Convert transitions from object to ES module [theme] Convert transitions from object to ES module Sep 6, 2020
@eps1lon
Copy link
Member Author

eps1lon commented Sep 7, 2020

Why going down this road, the module is private? Would it be simpler with?

Why not? We're currently mixing named exports with namespace exports. Might as well enable future optimizations.

Curious why consistency doesn't apply here all of the sudden.

Note that it also impacts zIndex, shadows, and shape.

Indeed but the fixes there are different. I spotted this weird pattern and moved to ES modules which incidentally fixes the mutation side-effects.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 7, 2020

@eps1lon No strong preferences, I was surprised to see the change, either way, It doesn't seem to make a significant difference, so happy either way.

Properties of keeping it as-is:

  • The shape of the object is known on the transitions.js file, this matches the code separation of the other parts of the theme (but private).
  • The transitions parts can be mutated (but private).

Properties of moving the es modules

  • The shape of the object is not known on the transitions.js file, this doesn't match the code separation of the other parts of the theme (but private).
  • The transitions parts can't be mutated (but private).

@eps1lon eps1lon force-pushed the fix/transitions-module branch from 67d3eb8 to 5d0776e Compare September 7, 2020 08:57
@eps1lon eps1lon merged commit 3b5302b into mui:next Sep 7, 2020
@eps1lon eps1lon deleted the fix/transitions-module branch September 7, 2020 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants