hypeserver / react-date-range

A React component for choosing dates and date ranges.
MIT License
2.59k stars 672 forks source link

Errors with react list at Calendar mount #375

Open bhritchie opened 4 years ago

bhritchie commented 4 years ago

Errors with react list at Calendar mount

I am seeing regular errors like this in production: null is not an object (evaluating 'this.list.getVisibleRange').

The error is that this.list is null in Calendar.focusToDate (https://github.com/Adphorus/react-date-range/blob/master/src/components/Calendar/index.js#L83), after being called from componentDidMount:

componentDidMount() {
  if (this.props.scroll.enabled) {
    // prevent react-list's initial render focus problem
    setTimeout(() => this.focusToDate(this.state.focusedDate));
  }
}

I note the comment: "prevent react-list's initial render focus problem" - I wonder if the 0ms timeout is not always sufficient? Does this seems like a likely cause, and, if so, can anyone suggest a resolution?

[BUG] Bug Reproduce Steps

I don't know how to reproduce the issue. I suspect it is a sporadic issue related to react-list not being available when componentDidMount runs.

[BUG] Expected behaviour

No error.

Environment

Package Version: 1.0.3 React version: 16.8.6 Browser: Various

Thanks in advance.

pofixifop commented 2 years ago

I also have this issue w/ the latest 1.4.0

index.js:152 Uncaught TypeError: Cannot read properties of null (reading 'getVisibleRange')
    at Calendar.focusToDate
HTaiNguyen commented 2 years ago

I'm having the same issue, any updates ?