Skip to content

fix(templates): prevent infinite redirect loop on unknown paths#15614

Closed
divyesh123-jain wants to merge 2 commits intopayloadcms:mainfrom
divyesh123-jain:fix/template-redirect-loop-next15
Closed

fix(templates): prevent infinite redirect loop on unknown paths#15614
divyesh123-jain wants to merge 2 commits intopayloadcms:mainfrom
divyesh123-jain:fix/template-redirect-loop-next15

Conversation

@divyesh123-jain
Copy link
Copy Markdown
Contributor

What?

Fixes infinite redirect loop on unknown/404 routes in production builds for templates with complex layouts (ecommerce, website, with-vercel-website).

Why?

In Next.js 15+, root layouts render statically by default. However, child components like AdminBar, Header, and Footer need runtime access to headers/cookies. This mismatch causes the layout to attempt re-rendering multiple times when users navigate to undefined routes in production builds, resulting in an infinite redirect loop and "too many redirects" browser error.

How?

Added await headers() at the start of the RootLayout function to force dynamic rendering, ensuring child components have access to runtime headers/cookies.

Changes:

  • templates/ecommerce/src/app/(app)/layout.tsx - Added headers import and await headers() call
  • templates/website/src/app/(frontend)/layout.tsx - Added headers to existing import and await headers() call
  • templates/with-vercel-website/src/app/(frontend)/layout.tsx - Added headers to existing import and await headers() call

@divyesh123-jain divyesh123-jain changed the title fix(templates): prevent infinite redirect loop on unknown paths fix(templates): prevent infinite redirect loop on unknown paths Feb 12, 2026
@paulpopus
Copy link
Copy Markdown
Contributor

This doesn't seem like the ideal fix to me:

  1. You have unrelated changes in the next package
  2. You're opting the entire frontend into dynamic rendering by calling the headers there

Closing on that basis

@paulpopus paulpopus closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants