From bbe3f900d9d98a2f8c5e7268e6cd9e7d033a3dc6 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 12 Jul 2019 15:42:23 -0700 Subject: [PATCH 1/2] Make sure to clean up listeners before overwriting clean up --- packages/next/client/link.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 833f34061a8ee..7bea253fd9d5d 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -54,6 +54,7 @@ export type LinkProps = { passHref?: boolean onError?: (error: Error) => void prefetch?: boolean + childRef?: React.RefObject } let observer: IntersectionObserver @@ -113,16 +114,13 @@ class Link extends Component { 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() }) From 7213658100c20d151b3a120681cecd9e61c517ec Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 12 Jul 2019 15:46:28 -0700 Subject: [PATCH 2/2] Remove separate change --- packages/next/client/link.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/client/link.tsx b/packages/next/client/link.tsx index 7bea253fd9d5d..ebc3990554c58 100644 --- a/packages/next/client/link.tsx +++ b/packages/next/client/link.tsx @@ -54,7 +54,6 @@ export type LinkProps = { passHref?: boolean onError?: (error: Error) => void prefetch?: boolean - childRef?: React.RefObject } let observer: IntersectionObserver