Skip to content

Commit 4a9c9e0

Browse files
committed
Removing pre-fetch logics as they are not working as expected
1 parent 8dcf648 commit 4a9c9e0

File tree

3 files changed

+1
-47
lines changed

3 files changed

+1
-47
lines changed

src/server/auth-client.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import {
8080
FetcherHooks,
8181
FetcherMinimalConfig
8282
} from "./fetcher.js";
83-
import { isPrefetch } from "./next-compat.js";
8483
import { AbstractSessionStore } from "./session/abstract-session-store.js";
8584
import { TransactionState, TransactionStore } from "./transaction-store.js";
8685
import { filterDefaultIdTokenClaims } from "./user.js";
@@ -401,9 +400,6 @@ export class AuthClient {
401400
) {
402401
return this.handleConnectAccount(req);
403402
} else {
404-
if (isPrefetch(req)) {
405-
return NextResponse.next();
406-
}
407403
// no auth handler found, simply touch the sessions
408404
// TODO: this should only happen if rolling sessions are enabled. Also, we should
409405
// try to avoid reading from the DB (for stateful sessions) on every request if possible.

src/server/next-compat.test.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NextRequest, NextResponse } from "next/server.js";
22
import { describe, expect, it } from "vitest";
33

4-
import { isPrefetch, toNextRequest, toNextResponse } from "./next-compat.js";
4+
import { toNextRequest, toNextResponse } from "./next-compat.js";
55

66
describe("next-compact", () => {
77
describe("toNextRequest", () => {
@@ -111,32 +111,4 @@ describe("next-compact", () => {
111111
expect(() => toNextResponse(fakeRes)).not.toThrow();
112112
});
113113
});
114-
115-
describe("isPrefetch", () => {
116-
it("should detect x-middleware-prefetch header", () => {
117-
const req = new Request("https://example.com", {
118-
headers: { "x-middleware-prefetch": "1" }
119-
});
120-
expect(isPrefetch(req)).toBe(true);
121-
});
122-
123-
it("should detect next-router-prefetch header", () => {
124-
const req = new Request("https://example.com", {
125-
headers: { "next-router-prefetch": "1" }
126-
});
127-
expect(isPrefetch(req)).toBe(true);
128-
});
129-
130-
it("should detect purpose=prefetch header", () => {
131-
const req = new Request("https://example.com", {
132-
headers: { purpose: "prefetch" }
133-
});
134-
expect(isPrefetch(req)).toBe(true);
135-
});
136-
137-
it("should return false when no prefetch-related headers are set", () => {
138-
const req = new Request("https://example.com");
139-
expect(isPrefetch(req)).toBe(false);
140-
});
141-
});
142114
});

src/server/next-compat.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,3 @@ export function toNextResponse(res: Response | NextResponse): NextResponse {
4949

5050
return nextRes;
5151
}
52-
53-
/**
54-
* Detect whether a request is a prefetch (Next.js router or browser prefetch).
55-
* Used to avoid unnecessary cookie writes or session logic.
56-
*
57-
* @internal
58-
*/
59-
export function isPrefetch(req: Request | NextRequest): boolean {
60-
const h = req.headers;
61-
if (h.get("x-middleware-prefetch") === "1") return true;
62-
if (h.get("next-router-prefetch") === "1") return true;
63-
if (h.get("purpose") === "prefetch") return true;
64-
return false;
65-
}

0 commit comments

Comments
 (0)