Skip to content

Commit

Permalink
fix weird route handler behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Mar 5, 2025
1 parent 141e447 commit 5f8af78
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/next/src/server/route-modules/app-route/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
type ActionStore,
} from '../../app-render/action-async-storage.external'
import * as sharedModules from './shared-modules'
import { getIsPotentialServerAction } from '../../lib/server-action-request-meta'
import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies'
import { cleanURL } from './helpers/clean-url'
import { StaticGenBailoutError } from '../../../client/components/static-generation-bailout'
Expand Down Expand Up @@ -294,7 +293,6 @@ export class AppRouteRouteModule extends RouteModule<

private async do(
handler: AppRouteHandlerFn,
actionStore: ActionStore,
workStore: WorkStore,
// @TODO refactor to not take this argument but instead construct the RequestStore
// inside this function. Right now we get passed a RequestStore even when
Expand Down Expand Up @@ -577,12 +575,14 @@ export class AppRouteRouteModule extends RouteModule<

// Return the redirect response.
return new Response(null, {
// If we're in an action, we want to use a 303 redirect as we don't
// want the POST request to follow the redirect, as it could result in
// We don't want POST requests to follow the redirect, as it could result in
// erroneous re-submissions.
status: actionStore.isAction
? RedirectStatusCode.SeeOther
: getRedirectStatusCodeFromError(err),
// NOTE: this used to accidentally happen because of a false-positive `isAction` check.
// We should consider removing it.
status:
request.method === 'POST'
? RedirectStatusCode.SeeOther
: getRedirectStatusCodeFromError(err),
headers,
})
} else if (isHTTPAccessFallbackError(err)) {
Expand Down Expand Up @@ -662,7 +662,7 @@ export class AppRouteRouteModule extends RouteModule<

const actionStore: ActionStore = {
isAppRoute: true,
isAction: getIsPotentialServerAction(req),
isAction: false,
}

const implicitTags = getImplicitTags(
Expand Down Expand Up @@ -753,7 +753,6 @@ export class AppRouteRouteModule extends RouteModule<
async () =>
this.do(
handler,
actionStore,
workStore,
requestStore,
implicitTags,
Expand Down

0 comments on commit 5f8af78

Please sign in to comment.