You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prevent app-breaking crashes when a page.tsx file lacks a valid default export
Allow developers to define a global fallback (e.g., app/fallback.tsx)
Improve developer experience and development-time safety in App Router projects
Non-Goals
This does not change how valid components are rendered
Does not replace not-found.tsx or error.tsx semantics
Does not add automatic file generation or CLI scaffolding
Background
In the current Next.js App Router design, each page.tsx must export a valid React component as a default export. If it does not, Next.js throws a fatal runtime error before hydration begins:
Error: The default export is not a React Component in "/[route]/page"
This error bypasses all user-defined boundaries like app/layout.tsx, app/error.tsx, or not-found.tsx, causing the app to crash completely. This issue most often occurs during development when routes are scaffolded before content is ready.
There is no way for developers to handle or bypass this failure gracefully, which conflicts with the resilience and flexibility goals of the App Router system.
Proposal
Introduce a global fallback mechanism to catch and render a safe UI when a route’s page.tsx exists but does not export a valid React component.
Implementation options:
• Allow app/fallback.tsx to be rendered if Next.js encounters a structural error when loading a route.
• Add a config flag: fallbackOnInvalidPage: true, which renders not-found.tsx instead of crashing.
• Add development-only leniency: show a warning and render an empty shell with a customizable banner.
I’d be happy to contribute or help test a canary version of this behavior. This feature would significantly improve DX, especially in monorepos, CMS-driven sites, and tools that scaffold routes dynamically.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
In the current Next.js App Router design, each page.tsx must export a valid React component as a default export. If it does not, Next.js throws a fatal runtime error before hydration begins:
This error bypasses all user-defined boundaries like app/layout.tsx, app/error.tsx, or not-found.tsx, causing the app to crash completely. This issue most often occurs during development when routes are scaffolded before content is ready.
There is no way for developers to handle or bypass this failure gracefully, which conflicts with the resilience and flexibility goals of the App Router system.
Proposal
Introduce a global fallback mechanism to catch and render a safe UI when a route’s page.tsx exists but does not export a valid React component.
Implementation options:
• Allow app/fallback.tsx to be rendered if Next.js encounters a structural error when loading a route.
• Add a config flag: fallbackOnInvalidPage: true, which renders not-found.tsx instead of crashing.
• Add development-only leniency: show a warning and render an empty shell with a customizable banner.
I’d be happy to contribute or help test a canary version of this behavior. This feature would significantly improve DX, especially in monorepos, CMS-driven sites, and tools that scaffold routes dynamically.
Beta Was this translation helpful? Give feedback.
All reactions