Skip to content

Commit

Permalink
Replace merge implementation in utils/styles with Object.assign
Browse files Browse the repository at this point in the history
The commit allows us to start using `Object.assign` for merging styles instead of this `mergeStyles` utility method. Chrome's currently has a bug in which its `Object.assign` implementation does not consistently or keys of merged objects. This sometimes led to styling bugs because some style properties rendered to the DOM in the wrong order (see mui#2986). This commit includes a babel transformation step that replaces all uses of `Object.assign` with the implementation at `simple-assign` and ignores the browser's native Object.assign implementation.

Signed-off-by: Neil Gabbadon <neil.gabbadon@emikra.com>
  • Loading branch information
newoga authored and heetvachhani committed Feb 4, 2016
1 parent cd258f2 commit 8b9d084
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"presets": ["es2015", "stage-1", "react"],
"plugins": [
["transform-replace-object-assign", "simple-assign"],
"transform-dev-warning",
"add-module-exports"
],
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"react-addons-pure-render-mixin": "^0.14.0",
"react-addons-transition-group": "^0.14.0",
"react-addons-update": "^0.14.0",
"simple-assign": "^0.1.0",
"warning": "^2.1.0"
},
"peerDependencies": {
Expand All @@ -59,6 +60,7 @@
"babel-plugin-transform-react-constant-elements": "^6.3.13",
"babel-plugin-transform-react-inline-elements": "^6.3.13",
"babel-plugin-transform-react-remove-prop-types": "^0.1.0",
"babel-plugin-transform-replace-object-assign": "^0.2.1",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
Expand Down
16 changes: 1 addition & 15 deletions src/utils/styles.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import autoPrefix from '../styles/auto-prefix';
import update from 'react-addons-update';
import warning from 'warning';

function mergeSingle(objA, objB) {
if (!objA) return objB;
if (!objB) return objA;
return update(objA, {$merge: objB});
}

export function mergeStyles(base, ...args) {
for (let i = 0; i < args.length; i++) {
if (args[i]) {
base = mergeSingle(base, args[i]);
}
}
return base;
}
export const mergeStyles = (...args) => Object.assign({}, ...args);

/**
* `mergeAndPrefix` is used to merge styles and autoprefix them. It has has been deprecated
Expand Down

0 comments on commit 8b9d084

Please sign in to comment.