Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

⚡️ Reduce prefetching (#2209)

Luke Vellaaa4a86f982ea
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/components/space-sidebar-menu.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/components/space-sidebar-menu.tsx
index 5b1b471e6..b81ba7319 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/components/space-sidebar-menu.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/components/space-sidebar-menu.tsx
@@ -9,7 +9,7 @@ import {
SidebarMenuButton,
SidebarMenuItem,
} from "@rallly/ui/sidebar";
-import Link from "next/link";
+import { HoverPrefetchLink } from "@/components/hover-prefetch-link";
import { useSpaceMenu } from "@/features/navigation/config";
export function SpaceSidebarMenu() {
@@ -28,12 +28,12 @@ export function SpaceSidebarMenu() {
return (
<SidebarMenuItem key={item.id}>
<SidebarMenuButton asChild isActive={item.isActive}>
- <Link href={item.href}>
+ <HoverPrefetchLink href={item.href}>
<Icon>
<item.icon />
</Icon>
{item.label}
- </Link>
+ </HoverPrefetchLink>
</SidebarMenuButton>
</SidebarMenuItem>
);
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx
index 4c25fad3c..23ca0f7e9 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/page.tsx
@@ -1,7 +1,6 @@
import { prisma } from "@rallly/database";
import { Tile, TileDescription, TileGrid, TileTitle } from "@rallly/ui/tile";
import type { Metadata } from "next";
-import Link from "next/link";
import {
BillingPageIcon,
CreatePageIcon,
@@ -17,6 +16,7 @@ import {
PageTitle,
} from "@/app/components/page-layout";
import { requireSpace, requireUser } from "@/auth/data";
+import { HoverPrefetchLink } from "@/components/hover-prefetch-link";
import { getUpcomingEventsCount } from "@/features/scheduled-event/data";
import { loadMembers } from "@/features/space/data";
import { defineAbilityForMember } from "@/features/space/member/ability";
@@ -93,12 +93,12 @@ export default async function Page() {
</h2>
<TileGrid>
<Tile asChild>
- <Link href="/new">
+ <HoverPrefetchLink href="/new">
<CreatePageIcon />
<TileTitle>
<Trans i18nKey="create" defaults="Create" />
</TileTitle>
- </Link>
+ </HoverPrefetchLink>
</Tile>
</TileGrid>
</div>
@@ -108,7 +108,7 @@ export default async function Page() {
</h2>
<TileGrid>
<Tile asChild>
- <Link href="/polls">
+ <HoverPrefetchLink href="/polls">
<PollPageIcon />
<TileTitle>
<Trans i18nKey="polls" defaults="Polls" />
@@ -120,11 +120,11 @@ export default async function Page() {
values={{ count: openPollCount }}
/>
</TileDescription>
- </Link>
+ </HoverPrefetchLink>
</Tile>
<Tile asChild>
- <Link href="/events">
+ <HoverPrefetchLink href="/events">
<EventPageIcon />
<TileTitle>
<Trans i18nKey="events" defaults="Events" />
@@ -136,7 +136,7 @@ export default async function Page() {
values={{ count: upcomingEventCount }}
/>
</TileDescription>
- </Link>
+ </HoverPrefetchLink>
</Tile>
</TileGrid>
</div>
@@ -146,16 +146,16 @@ export default async function Page() {
</h2>
<TileGrid>
<Tile asChild>
- <Link href="/settings/general">
+ <HoverPrefetchLink href="/settings/general">
<SettingsPageIcon />
<TileTitle>
<Trans i18nKey="settings" defaults="Settings" />
</TileTitle>
- </Link>
+ </HoverPrefetchLink>
</Tile>
<Tile asChild>
- <Link href="/settings/members">
+ <HoverPrefetchLink href="/settings/members">
<MembersPageIcon />
<TileTitle>
<Trans i18nKey="members" defaults="Members" />
@@ -167,13 +167,13 @@ export default async function Page() {
values={{ count: memberCount }}
/>
</TileDescription>
- </Link>
+ </HoverPrefetchLink>
</Tile>
<IfFeatureEnabled feature="billing">
{canManageBilling && (
<Tile asChild>
- <Link href="/settings/billing">
+ <HoverPrefetchLink href="/settings/billing">
<BillingPageIcon />
<TileTitle>
<Trans i18nKey="billing" defaults="Billing" />
@@ -185,7 +185,7 @@ export default async function Page() {
values={{ count: seatCount }}
/>
</TileDescription>
- </Link>
+ </HoverPrefetchLink>
</Tile>
)}
</IfFeatureEnabled>
diff --git a/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx b/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx
index cbe748129..296e0f721 100644
--- a/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx
@@ -20,8 +20,8 @@ import {
UserIcon,
UsersIcon,
} from "lucide-react";
-import Link from "next/link";
import { usePathname } from "next/navigation";
+import { HoverPrefetchLink } from "@/components/hover-prefetch-link";
import { Trans, useTranslation } from "@/i18n/client";
import { useFeatureFlag } from "@/lib/feature-flags/client";
@@ -71,10 +71,13 @@ export function AccountSidebarMenu() {
{menuItems.map((item) => (
<SidebarMenuItem key={item.id}>
<SidebarMenuButton asChild isActive={pathname.startsWith(item.href)}>
- <Link href={item.href} className="flex items-center gap-x-2">
+ <HoverPrefetchLink
+ href={item.href}
+ className="flex items-center gap-x-2"
+ >
<Icon>{item.icon}</Icon>
{item.label}
- </Link>
+ </HoverPrefetchLink>
</SidebarMenuButton>
</SidebarMenuItem>
))}
@@ -116,10 +119,13 @@ export function SpaceSidebarMenu() {
{menuItems.map((item) => (
<SidebarMenuItem key={item.id}>
<SidebarMenuButton asChild isActive={pathname.startsWith(item.href)}>
- <Link href={item.href} className="flex items-center gap-x-2">
+ <HoverPrefetchLink
+ href={item.href}
+ className="flex items-center gap-x-2"
+ >
<Icon>{item.icon}</Icon>
{item.label}
- </Link>
+ </HoverPrefetchLink>
</SidebarMenuButton>
</SidebarMenuItem>
))}
@@ -153,10 +159,13 @@ export function DeveloperSidebarMenu() {
asChild
isActive={pathname.startsWith(item.href)}
>
- <Link href={item.href} className="flex items-center gap-x-2">
+ <HoverPrefetchLink
+ href={item.href}
+ className="flex items-center gap-x-2"
+ >
<Icon>{item.icon}</Icon>
{item.label}
- </Link>
+ </HoverPrefetchLink>
</SidebarMenuButton>
</SidebarMenuItem>
))}
diff --git a/apps/web/src/components/hover-prefetch-link.tsx b/apps/web/src/components/hover-prefetch-link.tsx
new file mode 100644
index 000000000..b286fe21b
--- /dev/null
+++ b/apps/web/src/components/hover-prefetch-link.tsx
@@ -0,0 +1,25 @@
+"use client";
+
+import type { LinkProps } from "next/link";
+import Link from "next/link";
+import React from "react";
+
+export function HoverPrefetchLink({
+ children,
+ ...props
+}: LinkProps & { children?: React.ReactNode; className?: string }) {
+ const [active, setActive] = React.useState(false);
+
+ return (
+ <Link
+ {...props}
+ prefetch={active ? null : false}
+ onMouseEnter={(e) => {
+ setActive(true);
+ props.onMouseEnter?.(e);
+ }}
+ >
+ {children}
+ </Link>
+ );
+}
diff --git a/apps/web/src/components/poll/poll-footer.tsx b/apps/web/src/components/poll/poll-footer.tsx
index 4bff53e54..7067c00b4 100644
--- a/apps/web/src/components/poll/poll-footer.tsx
+++ b/apps/web/src/components/poll/poll-footer.tsx
@@ -19,6 +19,7 @@ export function PollFooter() {
components={{
a: (
<Link
+ prefetch={false}
className="rounded-none border-b border-b-gray-500 font-semibold hover:text-primary"
href="https://rallly.co"
/>
diff --git a/apps/web/src/features/poll/components/polls-infinite-list.tsx b/apps/web/src/features/poll/components/polls-infinite-list.tsx
index 78554857f..f072fd308 100644
--- a/apps/web/src/features/poll/components/polls-infinite-list.tsx
+++ b/apps/web/src/features/poll/components/polls-infinite-list.tsx
@@ -28,9 +28,9 @@ import {
StickerIcon,
TrashIcon,
} from "lucide-react";
-import Link from "next/link";
import React from "react";
import { CopyLinkButton } from "@/components/copy-link-button";
+import { HoverPrefetchLink } from "@/components/hover-prefetch-link";
import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
import { Spinner } from "@/components/spinner";
import { StackedList, StackedListItem } from "@/components/stacked-list";
@@ -68,13 +68,13 @@ function PollListItem({
<div className="grid w-full grid-cols-[1fr_auto] gap-2">
<div className="relative -m-4 flex min-w-0 flex-1 items-center gap-2 p-4">
<PollStatusIcon status={status} showTooltip={false} />
- <Link
+ <HoverPrefetchLink
className="min-w-0 text-sm hover:underline focus:ring-ring focus-visible:ring-2"
href={absoluteUrl(`/poll/${id}`)}
>
<span className="absolute inset-0" />
<span className="block truncate">{title}</span>
- </Link>
+ </HoverPrefetchLink>
</div>
<div className="hidden items-center justify-end gap-4 sm:flex">
{participants.length > 0 ? (