Skip to content

Commit

Permalink
Pass __nextDataReq in the middleware query params if already present (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vladiulianbogdan authored Jun 28, 2024
1 parent e4c7b6f commit 3a0bc84
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/open-next/src/core/routing/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,16 @@ export async function handleMiddleware(
} else {
const rewriteUrlObject = new URL(rewriteUrl);
newUrl = rewriteUrlObject.pathname;
//reset qs
middlewareQueryString = {};

// Reset the query params if the middleware is a rewrite
if (middlewareQueryString["__nextDataReq"]) {
middlewareQueryString = {
__nextDataReq: middlewareQueryString["__nextDataReq"],
};
} else {
middlewareQueryString = {};
}

rewriteUrlObject.searchParams.forEach((v: string, k: string) => {
middlewareQueryString[k] = v;
});
Expand Down

0 comments on commit 3a0bc84

Please sign in to comment.