react-notion-x icon indicating copy to clipboard operation
react-notion-x copied to clipboard

Search dialog could spin infinitely

Open sagan opened this issue 11 months ago • 0 comments
trafficstars

Description

In packages/react-notion-x/src/components/search-dialog.tsx, It throttles the actual search frequency to 1 request / per second. but the _onChangeQuery will always set isLoading state to false every time the input value changed, which may result in a spinning state infinitely.

Suggested fix

Replace throttle with debounce, and add the {trailing: true} option.

import debounce from 'lodash.debounce'

export class SearchDialog extends React.Component {
  componentDidMount() {
    this._search = debounce(this._searchImpl.bind(this), 1000, {trailing: true})
    this._warmupSearch()
  }
}

sagan avatar Nov 28 '24 06:11 sagan