Skip to content

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

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

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
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
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.

1 participant