react-pdf-highlighter icon indicating copy to clipboard operation
react-pdf-highlighter copied to clipboard

Bad callback if TipContainer deleted before callback complete

Open toastedcrumpets opened this issue 5 years ago • 0 comments

https://github.com/agentcooper/react-pdf-highlighter/blob/cd44de6c1652325a626776db72002a10b74e6369/packages/react-pdf-highlighter/src/components/TipContainer.js#L34

This line sets up a callback; however, if the TipContainer is deleted before the callback completes you get a "cannot use blah of undefined" error as the this is now pointing to the Window.

I fixed it like so:

timer = null;
componentDidMount() {
  this.timer = setTimeout(() => { this.updatePosition() }, 0);
}
componentWillUnmount() {
  clearTimeout(this.timer);
}

toastedcrumpets avatar May 15 '20 22:05 toastedcrumpets