Skip to content

Commit 44aacce

Browse files
committed
remove link prefetching
1 parent 497bc87 commit 44aacce

5 files changed

Lines changed: 47 additions & 27 deletions

File tree

app/_components/FeatureComponents/Sidebar/Parts/SharedItemsList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export const SharedItemsList = ({
167167
<Link
168168
key={`${sharedItem.id}-${sharedItem.category}`}
169169
href={getItemHref(fullItem)}
170+
prefetch={false}
170171
onClick={(e) => handleItemClick(e, fullItem)}
171172
data-sidebar-item-selected={isSelected}
172173
className={cn(

app/_components/FeatureComponents/Sidebar/Parts/SidebarItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export const SidebarItem = ({
202202
<div className="flex items-center group/item" style={style}>
203203
<Link
204204
href={itemHref}
205+
prefetch={false}
205206
onClick={handleClick}
206207
data-sidebar-item-selected={isSelected}
207208
className={cn(

app/_components/GlobalComponents/Sidebar/SidebarItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const SidebarItem = ({
2121
return (
2222
<Link
2323
href={href}
24+
prefetch={false}
2425
onClick={onClick}
2526
className={cn(
2627
"w-full flex items-center gap-3 px-3 py-2.5 text-md lg:text-sm rounded-jotty transition-colors",

app/api/serwist/[path]/route.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import { spawnSync } from "node:child_process";
21
import { createSerwistRoute } from "@serwist/turbopack";
32

4-
const revision = spawnSync("git", ["rev-parse", "HEAD"], {
5-
encoding: "utf-8",
6-
}).stdout?.trim() ?? crypto.randomUUID();
7-
83
export const { dynamic, dynamicParams, revalidate, generateStaticParams, GET } =
94
createSerwistRoute({
10-
additionalPrecacheEntries: [{ url: "/~offline", revision }],
115
swSrc: "app/sw.ts",
126
useNativeEsbuild: true,
137
nextConfig: {},

proxy.ts

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,43 @@ import { isEnvEnabled, isDebugFlag } from "./app/_utils/env-utils";
44

55
const debugProxy = isDebugFlag("proxy");
66

7+
const SESSION_CACHE_TTL = 10_000;
8+
const sessionCache = new Map<string, { valid: boolean; ts: number }>();
9+
10+
const _checkSession = async (sessionId: string, internalApiUrl: string, cookie: string) => {
11+
const cached = sessionCache.get(sessionId);
12+
if (cached && Date.now() - cached.ts < SESSION_CACHE_TTL) return cached.valid;
13+
14+
const sessionCheckUrl = new URL(`${internalApiUrl}/api/auth/check-session`);
15+
16+
if (debugProxy) {
17+
console.log("MIDDLEWARE - Session Check URL:", sessionCheckUrl.href);
18+
}
19+
20+
const res = await fetch(sessionCheckUrl, {
21+
headers: { Cookie: cookie },
22+
cache: "no-store",
23+
});
24+
25+
if (debugProxy) {
26+
console.log("MIDDLEWARE - Session Check Response:");
27+
console.log(" status:", res.status);
28+
console.log(" statusText:", res.statusText);
29+
console.log(" ok:", res.ok);
30+
}
31+
32+
sessionCache.set(sessionId, { valid: res.ok, ts: Date.now() });
33+
34+
if (sessionCache.size > 1000) {
35+
const now = Date.now();
36+
sessionCache.forEach((val, key) => {
37+
if (now - val.ts > SESSION_CACHE_TTL) sessionCache.delete(key);
38+
});
39+
}
40+
41+
return res.ok;
42+
};
43+
744
export const proxy = async (request: NextRequest) => {
845
const { pathname } = request.nextUrl;
946

@@ -61,27 +98,13 @@ export const proxy = async (request: NextRequest) => {
6198
console.log(" → Using:", internalApiUrl);
6299
}
63100

64-
const sessionCheckUrl = new URL(`${internalApiUrl}/api/auth/check-session`);
65-
66-
if (debugProxy) {
67-
console.log("MIDDLEWARE - Session Check URL:", sessionCheckUrl.href);
68-
}
69-
70-
const sessionCheck = await fetch(sessionCheckUrl, {
71-
headers: {
72-
Cookie: request.headers.get("Cookie") || "",
73-
},
74-
cache: "no-store",
75-
});
76-
77-
if (debugProxy) {
78-
console.log("MIDDLEWARE - Session Check Response:");
79-
console.log(" status:", sessionCheck.status);
80-
console.log(" statusText:", sessionCheck.statusText);
81-
console.log(" ok:", sessionCheck.ok);
82-
}
101+
const valid = await _checkSession(
102+
sessionId,
103+
internalApiUrl,
104+
request.headers.get("Cookie") || "",
105+
);
83106

84-
if (!sessionCheck.ok) {
107+
if (!valid) {
85108
const redirectResponse = NextResponse.redirect(loginUrl);
86109
redirectResponse.cookies.delete(cookieName);
87110

@@ -102,6 +125,6 @@ export const proxy = async (request: NextRequest) => {
102125

103126
export const config = {
104127
matcher: [
105-
"/((?!_next/static|_next/image|favicon.ico|site.webmanifest|sw.js|app-icons|app-screenshots|flags|fonts|images|repo-images|themes|openapi.yaml|~offline).*)",
128+
"/((?!_next/static|_next/image|favicon.ico|site.webmanifest|sw.js|app-icons|app-screenshots|flags|fonts|images|repo-images|themes|openapi.yaml).*)",
106129
],
107130
};

0 commit comments

Comments
 (0)