Skip to content

Commit

Permalink
Update link ref handling to clean up previous listeners (#7943)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Jul 14, 2019
1 parent 10614e8 commit 4adef73
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions packages/next/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,13 @@ class Link extends Component<LinkProps> {

cleanUpListeners = () => {}

componentDidMount() {
this.cleanUpListeners = () => {}
}

componentWillUnmount() {
this.cleanUpListeners()
}

handleRef(ref: Element) {
if (this.props.prefetch && IntersectionObserver && ref && ref.tagName) {
this.cleanUpListeners()
this.cleanUpListeners = listenToIntersections(ref, () => {
this.prefetch()
})
Expand Down

0 comments on commit 4adef73

Please sign in to comment.