Unverified Commit 0aa78292 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

add pathname normalizer for actions (#64592)

This adds a normalizer to handle `.action` invokes (when in minimal
mode). This PR by itself does not do anything of note, but will be
hooked up in a future PR in the [Next.js
builder](https://github.com/vercel/vercel/tree/main/packages/next).

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-3131
parent 1e3a1cba
...@@ -8,6 +8,7 @@ export const PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER = ...@@ -8,6 +8,7 @@ export const PRERENDER_REVALIDATE_ONLY_GENERATED_HEADER =
export const RSC_PREFETCH_SUFFIX = '.prefetch.rsc' export const RSC_PREFETCH_SUFFIX = '.prefetch.rsc'
export const RSC_SUFFIX = '.rsc' export const RSC_SUFFIX = '.rsc'
export const ACTION_SUFFIX = '.action'
export const NEXT_DATA_SUFFIX = '.json' export const NEXT_DATA_SUFFIX = '.json'
export const NEXT_META_SUFFIX = '.meta' export const NEXT_META_SUFFIX = '.meta'
export const NEXT_BODY_SUFFIX = '.body' export const NEXT_BODY_SUFFIX = '.body'
......
...@@ -126,6 +126,7 @@ import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-ass ...@@ -126,6 +126,7 @@ import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-ass
import { stripInternalHeaders } from './internal-utils' import { stripInternalHeaders } from './internal-utils'
import { RSCPathnameNormalizer } from './future/normalizers/request/rsc' import { RSCPathnameNormalizer } from './future/normalizers/request/rsc'
import { PostponedPathnameNormalizer } from './future/normalizers/request/postponed' import { PostponedPathnameNormalizer } from './future/normalizers/request/postponed'
import { ActionPathnameNormalizer } from './future/normalizers/request/action'
import { stripFlightHeaders } from './app-render/strip-flight-headers' import { stripFlightHeaders } from './app-render/strip-flight-headers'
import { import {
isAppPageRouteModule, isAppPageRouteModule,
...@@ -402,6 +403,7 @@ export default abstract class Server< ...@@ -402,6 +403,7 @@ export default abstract class Server<
protected readonly localeNormalizer?: LocaleRouteNormalizer protected readonly localeNormalizer?: LocaleRouteNormalizer
protected readonly normalizers: { protected readonly normalizers: {
readonly action: ActionPathnameNormalizer | undefined
readonly postponed: PostponedPathnameNormalizer | undefined readonly postponed: PostponedPathnameNormalizer | undefined
readonly rsc: RSCPathnameNormalizer | undefined readonly rsc: RSCPathnameNormalizer | undefined
readonly prefetchRSC: PrefetchRSCPathnameNormalizer | undefined readonly prefetchRSC: PrefetchRSCPathnameNormalizer | undefined
...@@ -496,6 +498,10 @@ export default abstract class Server< ...@@ -496,6 +498,10 @@ export default abstract class Server<
data: this.enabledDirectories.pages data: this.enabledDirectories.pages
? new NextDataPathnameNormalizer(this.buildId) ? new NextDataPathnameNormalizer(this.buildId)
: undefined, : undefined,
action:
this.enabledDirectories.app && this.minimalMode
? new ActionPathnameNormalizer()
: undefined,
} }
this.nextFontManifest = this.getNextFontManifest() this.nextFontManifest = this.getNextFontManifest()
...@@ -974,7 +980,7 @@ export default abstract class Server< ...@@ -974,7 +980,7 @@ export default abstract class Server<
let { pathname: urlPathname } = new URL(req.url, 'http://localhost') 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, // it's a data request the URL path will be the data URL,
// basePath is already stripped by this point // basePath is already stripped by this point
if (this.normalizers.data?.match(urlPathname)) { if (this.normalizers.data?.match(urlPathname)) {
...@@ -1431,6 +1437,10 @@ export default abstract class Server< ...@@ -1431,6 +1437,10 @@ export default abstract class Server<
normalizers.push(this.normalizers.rsc) normalizers.push(this.normalizers.rsc)
} }
if (this.normalizers.action) {
normalizers.push(this.normalizers.action)
}
for (const normalizer of normalizers) { for (const normalizer of normalizers) {
if (!normalizer.match(pathname)) continue if (!normalizer.match(pathname)) continue
......
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)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment