diff --git a/packages/next/src/lib/constants.ts b/packages/next/src/lib/constants.ts index ed3679d06273d..825cb114c7665 100644 --- a/packages/next/src/lib/constants.ts +++ b/packages/next/src/lib/constants.ts @@ -8,6 +8,7 @@ export const PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER = export const RSC_PREFETCH_SUFFIX = '.prefetch.rsc' export const RSC_SUFFIX = '.rsc' +export const ACTION_SUFFIX = '.action' export const NEXT_DATA_SUFFIX = '.json' export const NEXT_META_SUFFIX = '.meta' export const NEXT_BODY_SUFFIX = '.body' diff --git a/packages/next/src/server/base-server.ts b/packages/next/src/server/base-server.ts index 3a95c154ff6ae..16d03b945da12 100644 --- a/packages/next/src/server/base-server.ts +++ b/packages/next/src/server/base-server.ts @@ -124,6 +124,7 @@ import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-ass import { stripInternalHeaders } from './internal-utils' import { RSCPathnameNormalizer } from './future/normalizers/request/rsc' import { PostponedPathnameNormalizer } from './future/normalizers/request/postponed' +import { ActionPathnameNormalizer } from './future/normalizers/request/action' import { stripFlightHeaders } from './app-render/strip-flight-headers' import { isAppPageRouteModule, @@ -373,6 +374,7 @@ export default abstract class Server { protected readonly localeNormalizer?: LocaleRouteNormalizer protected readonly normalizers: { + readonly action: ActionPathnameNormalizer | undefined readonly postponed: PostponedPathnameNormalizer | undefined readonly rsc: RSCPathnameNormalizer | undefined readonly prefetchRSC: PrefetchRSCPathnameNormalizer | undefined @@ -467,6 +469,10 @@ export default abstract class Server { data: this.enabledDirectories.pages ? new NextDataPathnameNormalizer(this.buildId) : undefined, + action: + this.enabledDirectories.app && this.minimalMode + ? new ActionPathnameNormalizer() + : undefined, } this.nextFontManifest = this.getNextFontManifest() @@ -957,7 +963,7 @@ export default abstract class Server { let { pathname: urlPathname } = new URL(req.url, 'http://localhost') - // For ISR the URL is normalized to the prerenderPath so if + // For ISR the URL is normalized to the prerenderPath so if // it's a data request the URL path will be the data URL, // basePath is already stripped by this point if (this.normalizers.data?.match(urlPathname)) { @@ -1410,6 +1416,10 @@ export default abstract class Server { normalizers.push(this.normalizers.rsc) } + if (this.normalizers.action) { + normalizers.push(this.normalizers.action) + } + for (const normalizer of normalizers) { if (!normalizer.match(pathname)) continue diff --git a/packages/next/src/server/future/normalizers/request/action.ts b/packages/next/src/server/future/normalizers/request/action.ts new file mode 100644 index 0000000000000..07e14dedcd658 --- /dev/null +++ b/packages/next/src/server/future/normalizers/request/action.ts @@ -0,0 +1,13 @@ +import type { PathnameNormalizer } from './pathname-normalizer' + +import { ACTION_SUFFIX } from '../../../../lib/constants' +import { SuffixPathnameNormalizer } from './suffix' + +export class ActionPathnameNormalizer + extends SuffixPathnameNormalizer + implements PathnameNormalizer +{ + constructor() { + super(ACTION_SUFFIX) + } +}