payloadcms / payloadcms/payload
Fix included: Infinite redirect loop on unknown paths for templates
@paulpopus is already working on this.
Since Feb 11, 2026.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
Describe the Bug
For the other templates, I've seen issues like this being opened, so I assume each template using the same layout.tsx has this problem. -> tested ecommerce with mongo and d1 databases, however the same layout is used by other templates too.
Problem: Infinite redirect loops in production builds (npm run build), but works fine in dev mode.
Root layout renders statically by default in Next.js 15+, but child components (AdminBar, auth providers, Header) need access to runtime headers/cookies. This mismatch causes redirect loops.
Fix:
import { headers } from 'next/headers'
export default async function RootLayout({ children }) {
await headers() // Force dynamic rendering
Link to the code that reproduces this issue
pnpx create-payload-app@latest
Reproduction Steps
Use any template, build and start server (npm/pnpm run start)
Then go to any route that isn't defined, example: /asdasdasdasdasdadas
Which area(s) are affected?
area: templates
Environment Info
Binaries:
Node: 20.19.1
npm: 10.9.4
Yarn: 1.22.22
pnpm: 10.28.0
Relevant Packages:
payload: 3.75.0
next: 15.4.10
@payloadcms/db-d1-sqlite: 3.75.0
@payloadcms/db-mongodb: 3.75.0
@payloadcms/drizzle: 3.75.0
@payloadcms/email-resend: 3.75.0
@payloadcms/graphql: 3.75.0
@payloadcms/live-preview: 3.75.0
@payloadcms/live-preview-react: 3.75.0
@payloadcms/next/utilities: 3.75.0
@payloadcms/plugin-cloud-storage: 3.75.0
@payloadcms/plugin-form-builder: 3.75.0
@payloadcms/plugin-seo: 3.75.0
@payloadcms/richtext-lexical: 3.75.0
@payloadcms/storage-r2: 3.75.0
@payloadcms/storage-s3: 3.75.0
@payloadcms/translations: 3.75.0
@payloadcms/ui/shared: 3.75.0
react: 19.2.1
react-dom: 19.2.1
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Thu, 30 Oct 2025 23:29:50 +0000
Available memory (MB): 31513
Available CPU cores: 18
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.