Skip to content

Commit b84b184

Browse files
Merge pull request #1262 from mykonos-ibiza/fix-slow-navigation
fix: unnecessary prefetches and unnecessary RSCs
2 parents 0cb7469 + 9de8e0e commit b84b184

File tree

7 files changed

+52
-30
lines changed

7 files changed

+52
-30
lines changed
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
import { maintenanceNoticeFlag } from '@/lib/edge-flags';
21
import DashboardLayoutContent from '@/components/dashboard/layout-content';
3-
import { cookies } from 'next/headers';
42

53
interface DashboardLayoutProps {
64
children: React.ReactNode;
75
}
86

9-
const getMaintenanceNotice = async () => {
10-
const maintenanceNotice = await maintenanceNoticeFlag();
11-
return maintenanceNotice;
12-
};
13-
14-
export default async function DashboardLayout({
7+
export default function DashboardLayout({
158
children,
169
}: DashboardLayoutProps) {
17-
await cookies();
18-
const maintenanceNotice = await getMaintenanceNotice();
19-
return (
20-
<DashboardLayoutContent maintenanceNotice={maintenanceNotice}>
21-
{children}
22-
</DashboardLayoutContent>
23-
);
10+
return <DashboardLayoutContent>{children}</DashboardLayoutContent>;
2411
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { maintenanceNoticeFlag } from '@/lib/edge-flags';
2+
import { NextResponse } from 'next/server';
3+
4+
export async function GET() {
5+
const maintenanceNotice = await maintenanceNoticeFlag();
6+
return NextResponse.json(maintenanceNotice);
7+
}

frontend/src/components/dashboard/layout-content.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,29 @@ import { useApiHealth } from '@/hooks/react-query';
1313
import { MaintenancePage } from '@/components/maintenance/maintenance-page';
1414
import { DeleteOperationProvider } from '@/contexts/DeleteOperationContext';
1515
import { StatusOverlay } from '@/components/ui/status-overlay';
16-
import type { IMaintenanceNotice } from '@/lib/edge-flags';
1716
import { MaintenanceNotice } from './maintenance-notice';
1817
import { MaintenanceBanner } from './maintenance-banner';
18+
import { useMaintenanceNoticeQuery } from '@/hooks/react-query/edge-flags';
1919

2020
interface DashboardLayoutContentProps {
2121
children: React.ReactNode;
22-
maintenanceNotice: IMaintenanceNotice;
2322
}
2423

2524
export default function DashboardLayoutContent({
2625
children,
27-
maintenanceNotice,
2826
}: DashboardLayoutContentProps) {
27+
const maintenanceNoticeQuery = useMaintenanceNoticeQuery();
2928
// const [showPricingAlert, setShowPricingAlert] = useState(false)
3029
const [showMaintenanceAlert, setShowMaintenanceAlert] = useState(false);
3130
const { data: accounts } = useAccounts();
3231
const personalAccount = accounts?.find((account) => account.personal_account);
3332
const { user, isLoading } = useAuth();
3433
const router = useRouter();
35-
const { data: healthData, isLoading: isCheckingHealth, error: healthError } = useApiHealth();
34+
const {
35+
data: healthData,
36+
isLoading: isCheckingHealth,
37+
error: healthError,
38+
} = useApiHealth();
3639

3740
useEffect(() => {
3841
// setShowPricingAlert(false)
@@ -49,10 +52,10 @@ export default function DashboardLayoutContent({
4952
}
5053
}, [user, isLoading, router]);
5154

52-
if (maintenanceNotice.enabled) {
55+
if (maintenanceNoticeQuery.data?.enabled) {
5356
const now = new Date();
54-
const startTime = maintenanceNotice.startTime;
55-
const endTime = maintenanceNotice.endTime;
57+
const startTime = new Date(maintenanceNoticeQuery.data.startTime);
58+
const endTime = new Date(maintenanceNoticeQuery.data.endTime);
5659

5760
if (now > startTime) {
5861
return (
@@ -66,11 +69,11 @@ export default function DashboardLayoutContent({
6669
}
6770

6871
let mantenanceBanner: React.ReactNode | null = null;
69-
if (maintenanceNotice.enabled) {
72+
if (maintenanceNoticeQuery.data?.enabled) {
7073
mantenanceBanner = (
7174
<MaintenanceBanner
72-
startTime={maintenanceNotice.startTime.toISOString()}
73-
endTime={maintenanceNotice.endTime.toISOString()}
75+
startTime={maintenanceNoticeQuery.data.startTime}
76+
endTime={maintenanceNoticeQuery.data.endTime}
7477
/>
7578
);
7679
}

frontend/src/components/sidebar/nav-agents.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ export function NavAgents() {
428428
onClick={(e) =>
429429
handleThreadClick(e, thread.threadId, thread.url)
430430
}
431+
prefetch={false}
431432
className="flex items-center flex-1 min-w-0"
432433
>
433434
{isThreadLoading ? (

frontend/src/components/sidebar/search-search.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export function SidebarSearch() {
236236
onClick={(e) =>
237237
handleThreadClick(e, thread.threadId, thread.url)
238238
}
239+
prefetch={false}
239240
className="flex items-center justify-between w-full"
240241
>
241242
<div className="flex items-center">
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use client';
2+
3+
import { createQueryHook, createQueryKeys } from '@/hooks/use-query';
4+
import { IMaintenanceNotice } from '@/lib/edge-flags';
5+
6+
const maintenanceNoticeKeysBase = ['maintenance-notice'] as const;
7+
8+
export const maintenanceNoticeKeys = createQueryKeys({
9+
all: maintenanceNoticeKeysBase,
10+
});
11+
12+
export const useMaintenanceNoticeQuery = createQueryHook(
13+
maintenanceNoticeKeys.all,
14+
async (): Promise<IMaintenanceNotice> => {
15+
const response = await fetch('/api/edge-flags');
16+
return response.json();
17+
},
18+
{
19+
staleTime: 30 * 1000,
20+
refetchInterval: 60 * 1000,
21+
refetchOnWindowFocus: true,
22+
retry: 3,
23+
},
24+
);

frontend/src/lib/edge-flags.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { getAll } from '@vercel/edge-config';
44
export type IMaintenanceNotice =
55
| {
66
enabled: true;
7-
startTime: Date;
8-
endTime: Date;
7+
startTime: string; // Date
8+
endTime: string; // Date
99
}
1010
| {
1111
enabled: false;
@@ -18,7 +18,6 @@ export const maintenanceNoticeFlag = flag({
1818
async decide() {
1919
try {
2020
if (!process.env.EDGE_CONFIG) {
21-
console.warn('Edge config is not set');
2221
return { enabled: false } as const;
2322
}
2423

@@ -43,8 +42,8 @@ export const maintenanceNoticeFlag = flag({
4342

4443
return {
4544
enabled: true,
46-
startTime,
47-
endTime,
45+
startTime: startTime.toISOString(),
46+
endTime: endTime.toISOString(),
4847
} as const;
4948
} catch (cause) {
5049
console.error(

0 commit comments

Comments
 (0)