Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/healthy-clouds-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': major
---

Added flushSync call to state updates in Scrollable component. This would probably be a breaking change? :(
22 changes: 16 additions & 6 deletions polaris-react/src/components/Scrollable/Scrollable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {Component} from 'react';
import {flushSync} from 'react-dom';

import {debounce} from '../../utilities/debounce';
import {classNames} from '../../utilities/css';
Expand Down Expand Up @@ -96,8 +97,15 @@ export class Scrollable extends Component<ScrollableProps, State> {
}

componentDidUpdate() {
if (!this.scrollArea) {
return;
}

const {scrollPosition} = this.state;
if (scrollPosition && this.scrollArea && scrollPosition > 0) {
const availableScrollHeight =
this.scrollArea.scrollHeight - this.scrollArea.clientHeight;

if (scrollPosition > 0 && scrollPosition < availableScrollHeight) {
this.scrollArea.scrollTop = scrollPosition;
}
}
Expand Down Expand Up @@ -171,11 +179,13 @@ export class Scrollable extends Component<ScrollableProps, State> {
onScrolledToBottom();
}

this.setState({
topShadow: shouldTopShadow,
bottomShadow: shouldBottomShadow,
scrollPosition: scrollTop,
canScroll,
flushSync(() => {
this.setState({
topShadow: shouldTopShadow,
bottomShadow: shouldBottomShadow,
scrollPosition: scrollTop,
canScroll,
});
});
};

Expand Down