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

always do a second render for SSR compatible #22

Merged
merged 1 commit into from
May 1, 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
43 changes: 23 additions & 20 deletions src/BaseTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class BaseTable extends React.PureComponent {

const { columns, children, expandedRowKeys, defaultExpandedRowKeys } = props;
this.state = {
scrollbarSize: 0,
hoveredRowKey: null,
resizingKey: null,
resizingWidth: 0,
Expand Down Expand Up @@ -96,7 +97,6 @@ class BaseTable extends React.PureComponent {
this._horizontalScrollbarSize = 0;
this._verticalScrollbarSize = 0;
this._scrollbarPresenceChanged = false;
this._scrollbarSizeMeasured = getScrollbarSize() !== undefined;
}

/**
Expand Down Expand Up @@ -629,13 +629,10 @@ class BaseTable extends React.PureComponent {
}

componentDidMount() {
// in SSR getScrollbarSize() === undefined, so we have to measure again here
if (!this._scrollbarSizeMeasured) {
getScrollbarSize();
this.setState({});
const scrollbarSize = getScrollbarSize();
if (scrollbarSize > 0) {
this.setState({ scrollbarSize });
}

this._maybeScrollbarPresenceChange();
}

componentDidUpdate(prevProps, prevState) {
Expand Down Expand Up @@ -708,28 +705,34 @@ class BaseTable extends React.PureComponent {

_calcScrollbarSizes() {
const { fixed, width } = this.props;
const { scrollbarSize } = this.state;

const totalRowsHeight = this.getTotalRowsHeight();
const totalColumnsWidth = this.getTotalColumnsWidth();
const scrollbarSize = getScrollbarSize() || 0;

const prevHorizontalScrollbarSize = this._horizontalScrollbarSize;
const prevVerticalScrollbarSize = this._verticalScrollbarSize;

// we have to set `this._horizontalScrollbarSize` before calling `this._getBodyHeight`
if (!fixed || totalColumnsWidth <= width - scrollbarSize) {
if (scrollbarSize === 0) {
this._horizontalScrollbarSize = 0;
this._verticalScrollbarSize = totalRowsHeight > this._getBodyHeight() ? scrollbarSize : 0;
this._verticalScrollbarSize = 0;
} else {
if (totalColumnsWidth > width) {
this._horizontalScrollbarSize = scrollbarSize;
this._verticalScrollbarSize =
totalRowsHeight > this._getBodyHeight() - this._horizontalScrollbarSize ? scrollbarSize : 0;
} else {
// we have to set `this._horizontalScrollbarSize` before calling `this._getBodyHeight`
if (!fixed || totalColumnsWidth <= width - scrollbarSize) {
this._horizontalScrollbarSize = 0;
this._verticalScrollbarSize = 0;
if (totalRowsHeight > this._getBodyHeight()) {
this._verticalScrollbarSize = totalRowsHeight > this._getBodyHeight() ? scrollbarSize : 0;
} else {
if (totalColumnsWidth > width) {
this._horizontalScrollbarSize = scrollbarSize;
this._verticalScrollbarSize = scrollbarSize;
this._verticalScrollbarSize =
totalRowsHeight > this._getBodyHeight() - this._horizontalScrollbarSize ? scrollbarSize : 0;
} else {
this._horizontalScrollbarSize = 0;
this._verticalScrollbarSize = 0;
if (totalRowsHeight > this._getBodyHeight()) {
this._horizontalScrollbarSize = scrollbarSize;
this._verticalScrollbarSize = scrollbarSize;
}
}
}
}
Expand All @@ -748,7 +751,7 @@ class BaseTable extends React.PureComponent {
this._scrollbarPresenceChanged = false;

onScrollbarPresenceChange({
size: getScrollbarSize(),
size: this.state.scrollbarSize,
horizontal: this._horizontalScrollbarSize > 0,
vertical: this._verticalScrollbarSize > 0,
});
Expand Down