React-virtualized: Scrolling to top on component render

Created on 13 Nov 2017  路  3Comments  路  Source: bvaughn/react-virtualized

Hi. I am new to react so this issue might be something obvious for others. I have done some research but could not find a solution on my own.

I have created a simple component showing a table as in Table.Example.js from the source. I have not added anything else and not passing any props to this specific component.

What happen is the following:

1) I scroll down the main page and also select (it's outlined) and scroll down the table, then if react triggers a render because of some changes in the props passed down by parents, the page scroll position is set to the top.

2) I scroll down the main page and scroll the table but do not leave it selected (it's not outlined), the above behaviours does not happen. The page is rendered again on props changes but the scroll position is not changed.

Any advice?

bug duplicate

Most helpful comment

For the moment I've fixed it with something like this, but I am unsure whether is the correct solution.

    scrollPosition = 0

    componentWillReceiveProps () {
      const element = ReactDOM.findDOMNode(this);
      if (element != null) {
        this.scrollPosition = window.scrollY
      }
    }

    componentDidUpdate () {
      const element = ReactDOM.findDOMNode(this);
      if (element != null) {
        window.scrollTo(0, this.scrollPosition)
      }
    }

All 3 comments

For the moment I've fixed it with something like this, but I am unsure whether is the correct solution.

    scrollPosition = 0

    componentWillReceiveProps () {
      const element = ReactDOM.findDOMNode(this);
      if (element != null) {
        this.scrollPosition = window.scrollY
      }
    }

    componentDidUpdate () {
      const element = ReactDOM.findDOMNode(this);
      if (element != null) {
        window.scrollTo(0, this.scrollPosition)
      }
    }

There seems to be a bug in 9.12 with scrollPosition causing the scroll offset to get stuck. Probably a regression from a recent change to the way that property is handled.

Going to close this as a duplicate of #884. I'm pretty sure the underlying cause is the same, and the issue has a repro case attached.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ms007 picture ms007  路  4Comments

clauderic picture clauderic  路  3Comments

rodcorsi picture rodcorsi  路  3Comments

johnnyji picture johnnyji  路  3Comments

zllc picture zllc  路  3Comments