Unverified Commit 4adef73a authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update link ref handling to clean up previous listeners (#7943)

parent 10614e84
...@@ -113,16 +113,13 @@ class Link extends Component<LinkProps> { ...@@ -113,16 +113,13 @@ class Link extends Component<LinkProps> {
cleanUpListeners = () => {} cleanUpListeners = () => {}
componentDidMount() {
this.cleanUpListeners = () => {}
}
componentWillUnmount() { componentWillUnmount() {
this.cleanUpListeners() this.cleanUpListeners()
} }
handleRef(ref: Element) { handleRef(ref: Element) {
if (this.props.prefetch && IntersectionObserver && ref && ref.tagName) { if (this.props.prefetch && IntersectionObserver && ref && ref.tagName) {
this.cleanUpListeners()
this.cleanUpListeners = listenToIntersections(ref, () => { this.cleanUpListeners = listenToIntersections(ref, () => {
this.prefetch() this.prefetch()
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment