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

optimizations: setState in lifecycles + forced reflow #556

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Draggable.js
Expand Up @@ -236,7 +236,9 @@ class Draggable extends React.Component<DraggableProps, DraggableState> {
}

componentWillUnmount() {
this.setState({dragging: false}); // prevents invariant if unmounted while dragging
if (this.state.dragging) {
this.setState({dragging: false}); // prevents invariant if unmounted while dragging
}
}

// React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
Expand Down
11 changes: 10 additions & 1 deletion lib/DraggableCore.js
Expand Up @@ -258,7 +258,16 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
removeEvent(ownerDocument, eventsFor.mouse.stop, this.handleDragStop);
removeEvent(ownerDocument, eventsFor.touch.stop, this.handleDragStop);
removeEvent(thisNode, eventsFor.touch.start, this.onTouchStart, {passive: false});
if (this.props.enableUserSelectHack) removeUserSelectStyles(ownerDocument);
if (this.props.enableUserSelectHack) {
// prevent a possible "forced reflow"
if (window.requestAnimationFrame) {
window.requestAnimationFrame(() => {
removeUserSelectStyles(ownerDocument);
});
} else {
removeUserSelectStyles(ownerDocument);
}
}
}
}

Expand Down