From dcee56ff80636f42ab45fd997deb2dd39d6d9ccd Mon Sep 17 00:00:00 2001 From: Marko Mitranic Date: Sat, 2 Nov 2024 00:42:33 +0100 Subject: [PATCH] Skip redirectionio for server actions and components --- middleware.js | 5 +++++ middleware.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/middleware.js b/middleware.js index dd50300..3b66f66 100644 --- a/middleware.js +++ b/middleware.js @@ -53,6 +53,11 @@ export const createRedirectionIoMiddleware = (config) => { if (!useFetch) { return response ?? next(); } + // Disable for server-actions and components. + if (request.headers.get('Next-Action')?.length || request.headers.get('Accept') === "text/x-component") { + return response ?? next(); + } + const fetchResponse = await fetch(request, { redirect: "manual", cache: "no-store", diff --git a/middleware.ts b/middleware.ts index b168236..b712529 100644 --- a/middleware.ts +++ b/middleware.ts @@ -80,6 +80,10 @@ export const createRedirectionIoMiddleware = (config: CreateMiddlewareConfig): M if (!useFetch) { return response ?? next(); } + // Disable for server-actions and components. + if (request.headers.get('Next-Action')?.length || request.headers.get('Accept') === "text/x-component") { + return response ?? next(); + } const fetchResponse = await fetch(request, { redirect: "manual",