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

Fix case when scrollToPosition will not update internal state in React >= 16.4. #1288

Merged
merged 1 commit into from
May 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions source/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ type InstanceProps = {
prevIsScrolling: boolean,
prevScrollToColumn: number,
prevScrollToRow: number,
prevScrollLeft: ?number,
prevScrollTop: ?number,

columnSizeAndPositionManager: ScalingCellSizeAndPositionManager,
rowSizeAndPositionManager: ScalingCellSizeAndPositionManager,
Expand Down Expand Up @@ -343,15 +345,17 @@ class Grid extends React.PureComponent<Props, State> {
prevIsScrolling: props.isScrolling === true,
prevScrollToColumn: props.scrollToColumn,
prevScrollToRow: props.scrollToRow,
prevScrollLeft: props.scrollLeft,
prevScrollTop: props.scrollTop,

scrollbarSize: 0,
scrollbarSizeMeasured: false,
},
isScrolling: false,
scrollDirectionHorizontal: SCROLL_DIRECTION_FORWARD,
scrollDirectionVertical: SCROLL_DIRECTION_FORWARD,
scrollLeft: 0,
scrollTop: 0,
scrollLeft: props.scrollLeft || 0,
scrollTop: props.scrollTop || 0,
scrollPositionChangeReason: null,

needToResetStyleCache: false,
Expand Down Expand Up @@ -821,6 +825,7 @@ class Grid extends React.PureComponent<Props, State> {
prevState: State,
): $Shape<State> {
const newState = {};
let {instanceProps} = prevState;

if (
(nextProps.columnCount === 0 && prevState.scrollLeft !== 0) ||
Expand All @@ -832,9 +837,10 @@ class Grid extends React.PureComponent<Props, State> {
// only use scroll{Left,Top} from props if scrollTo{Column,Row} isn't specified
// scrollTo{Column,Row} should override scroll{Left,Top}
} else if (
(nextProps.scrollLeft !== prevState.scrollLeft &&
(nextProps.scrollLeft !== instanceProps.prevScrollLeft &&
nextProps.scrollToColumn < 0) ||
(nextProps.scrollTop !== prevState.scrollTop && nextProps.scrollToRow < 0)
(nextProps.scrollTop !== instanceProps.prevScrollTop &&
nextProps.scrollToRow < 0)
) {
Object.assign(
newState,
Expand All @@ -846,8 +852,6 @@ class Grid extends React.PureComponent<Props, State> {
);
}

let {instanceProps} = prevState;

// Initially we should not clearStyleCache
newState.needToResetStyleCache = false;
if (
Expand Down Expand Up @@ -944,6 +948,8 @@ class Grid extends React.PureComponent<Props, State> {
instanceProps.prevRowHeight = nextProps.rowHeight;
instanceProps.prevScrollToColumn = nextProps.scrollToColumn;
instanceProps.prevScrollToRow = nextProps.scrollToRow;
instanceProps.prevScrollLeft = nextProps.scrollLeft;
instanceProps.prevScrollTop = nextProps.scrollTop;

// getting scrollBarSize (moved from componentWillMount)
instanceProps.scrollbarSize = nextProps.getScrollbarSize();
Expand Down