Skip to content

Commit

Permalink
Do not prefetch when targetLink == null
Browse files Browse the repository at this point in the history
  • Loading branch information
SamChou19815 committed Mar 17, 2021
1 parent 5ff1abe commit 97513ba
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/docusaurus/src/client/exports/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,26 @@ function Link({
if (IOSupported && ref && isInternal) {
// If IO supported and element reference found, setup Observer functionality.
handleIntersection(ref, () => {
window.docusaurus.prefetch(targetLink || '');
if (targetLink != null) {
window.docusaurus.prefetch(targetLink);
}
});
}
};

const onMouseEnter = () => {
if (!preloaded.current) {
window.docusaurus.preload(targetLink || '');
if (!preloaded.current && targetLink != null) {
window.docusaurus.preload(targetLink);
preloaded.current = true;
}
};

useEffect(() => {
// If IO is not supported. We prefetch by default (only once).
if (!IOSupported && isInternal) {
window.docusaurus.prefetch(targetLink || '');
if (targetLink != null) {
window.docusaurus.prefetch(targetLink);
}
}

// When unmounting, stop intersection observer from watching.
Expand Down

0 comments on commit 97513ba

Please sign in to comment.