Repository navigation
fix(next): support next.config trailingSlash - #18207
Merged
Merged
Conversation
Setting `trailingSlash: true` in `next.config` was 308-redirecting every Payload API and admin request to its trailing-slash form, breaking admin saves and rendering middleware workarounds ineffective (Next applies the redirect before middleware runs). `withPayload` now mirrors `nextConfig.trailingSlash` into the `NEXT_TRAILING_SLASH` env var the same way `basePath` is threaded. `formatAdminURL` appends a trailing slash to the URLs it generates when that env var is set, so admin/API clients hit the canonical URL directly and Next never emits the redirect. Public-page behavior is unchanged.
Adds a `test/trailing-slash` config that runs Next.js with `trailingSlash: true` to exercise the bug fix end-to-end. Verifies that admin form actions and API mutation requests include the trailing slash directly so Next.js never emits a 308 normalization redirect, which was the source of the original silent admin-save failure.
Two follow-ups to make `trailingSlash: true` actually round-trip end-to-end: - `handleEndpoints` now strips a single trailing slash from both the incoming pathname and the API base path before string-slicing, so `/api/users/login/` (the canonical form under trailingSlash:true) reaches the same endpoint match as `/api/users/login`. Without this the slug shift skipped the collection segment and produced 404s. - `Root/index.tsx` normalizes `currentRoute` and `createFirstUserRoute` before comparing them to the raw `adminRoute` config value, so the dashboard view is selected when navigating to `/admin/`. Also extends `test/trailing-slash` with the Next.js app boilerplate needed for it to boot under its own next.config (the test directory gets its own admin/api route handlers when it overrides next.config.mjs) and broadens the e2e to walk dashboard, list, edit, account and verify no /api response is a 3xx.
JarrodMFlesch
requested review from
AlessioGr,
denolfe and
jacobsfletch
as code owners
September 18, 2026 13:59
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
nathanlentz
approved these changes
Sep 18, 2026
Contributor
|
🚀 This is included in version v3.90.2 |
Contributor
|
I'm using Payload v3 with Next.js's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Identical to #16432, back-ported for 3.x.