Skip to content

Commit e4d810c

Browse files
committed
fix: do not mutate tempArray when creating handles - issue #115
Even if component is defined with defaultValue bigger than 0, the handle can be rendered at position `left: 0px`. The render method of react-slider component is called twice at the beginning because of handleResize event which calls setState. On first render, it calculates left as 0, second render sets correct left value. The issue occurs in React version 16, which implements optimized diffing of DOM changes. Handle components are not rerendered second time, because they are returned as mutated tempArray. It means that the object reference of handle components is not changed between first and second render. And react 16 evaluates it as no change DOM change.
1 parent 5e85579 commit e4d810c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

react-slider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@
758758
styles[i] = this._buildHandleStyle(offset[i], i);
759759
}
760760

761-
var res = this.tempArray;
761+
var res = [];
762762
var renderHandle = this._renderHandle;
763763
if (React.Children.count(this.props.children) > 0) {
764764
React.Children.forEach(this.props.children, function (child, i) {

0 commit comments

Comments
 (0)