Skip to content

Commit

Permalink
Handle prefetch in user code to have proper ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
cramforce committed Oct 21, 2024
1 parent cab4cf8 commit c7fe161
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/ui/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export const Link: typeof NextLink = (({ children, ...props }) => {
const entry = entries[0];
if (entry.isIntersecting) {
// Set a timeout to trigger prefetch after 1 second
prefetchTimeout = setTimeout(() => {
prefetchTimeout = setTimeout(async () => {
router.prefetch(String(props.href));
await sleep(0); // We want the doc prefetches to happen first.
void prefetchImages(String(props.href)).then((images) => {
setImages(images);
}, console.error);
Expand Down Expand Up @@ -82,7 +84,9 @@ export const Link: typeof NextLink = (({ children, ...props }) => {
return (
<NextLink
ref={linkRef}
prefetch={false}
onMouseOver={() => {
router.prefetch(String(props.href));
for (const image of images) {
if (image.loading === "lazy" || seen.has(image.srcset)) {
continue;
Expand Down

0 comments on commit c7fe161

Please sign in to comment.