-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch-all route also catches static assets #67806
Comments
This also seems to be happening on the pages router, One another observation it doesn't always happen, so might be a weird race condition somewhere, I am seeing intermittent 200s for such routes. |
Its there in canary.103 as well. Any workaround for the time being?? and doesn't seem to be intermittent. |
Hadn't found a workaround. As I was using next only for a marketing website I completely switched the framework. |
I encountered a similar issue with a CMS backend where the app/[...catch-all] route was also capturing the _next directory, especially when there were missing assets. I mitigated this by checking the slug path and returning early. However, this approach still returns a 200 status code even if a file is missing or the api endpoint is not there const PageResolver = ({params}: PageProps) => {
const firstSlug = params.slug[0];
const reservedPaths = ['_next', 'api', 'sites'];
if (reservedPaths.includes(firstSlug)) {
return;
}
const slug = params.slug.join('/');
return (
<>
<NodePages slug={slug} byAlias={true} />
</>
);
}; The problem is in the log now i get GET / 200 in 121ms
GET /favicon.ico 200 in 10ms
GET /sites/default/files/pictures/oem/ibm/printers/4610/2cr_cut-assy-wire.jpg 200 in 54ms
✓ Compiled in 291ms (883 modules)
✓ Compiled in 316ms (883 modules)
This is happening even in dev mode. |
I'm encountering this issue too, the router catches all .js.map files and seems to override my public assets like favicons. My workaround atm is to do the following: // /constants.ts
export const NEXTJS_EXPLICIT_IGNORED_ROUTES = [
'favicon.ico',
'favicon-48x48.png',
'favicon.svg',
'apple-touch-icon.png',
'site.webmanifest',
];
export const NEXTJS_IGNORED_PATTERNS = [
'.js',
'.mjs',
'.map',
'.css',
'.json',
'.png',
'.jpg',
'.jpeg',
'.gif',
'.webp',
'.ico',
'.svg',
]; Then in my page: // /[slug]/page.tsx
export default async function UniversalPage({ params }: PageProps) {
const slug = params.slug;
if (
NEXTJS_EXPLICIT_IGNORED_ROUTES.includes(slug) ||
NEXTJS_IGNORED_PATTERNS.some((pattern) => slug.includes(pattern))
) {
return;
}
return <div>Render this</div>
} Happens in dev mode and when build. I feel like this is a pretty serious issue, there's surely a better way to handle this without a janky workaround. Would love to know if there's something I'm just missing or if this is a bug? |
I faced the same issue upgrading Next.js from Any updates here? |
Hi everyone— With The minimal server does not copy the public or .next/static folders by default as these should ideally be handled by a CDN instead, although these folders can be copied to the standalone/public and standalone/.next/static folders manually, after which server.js file will serve these automatically. To copy these and then start this local minimal server locally, you can do something like this:
I am not seeing any issues when the I have also just created a PR to update our documentation with this → #72432. I will closing this PR since this is a non-issue! |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
https://github.com/r6203/next-catch-all-bug
To Reproduce
Current vs. Expected behavior
Having a catch all route at the root of the app shouldn't intercept next generated assets.
Expect a working app where each non asset request resolves to the catch-all route but requests to next generated assets (_next/**/*) to resolve to the corresponding files.
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Fri, 12 Jul 2024 00:06:53 +0000 Available memory (MB): 32023 Available CPU cores: 12 Binaries: Node: 22.4.1 npm: 10.8.1 Yarn: N/A pnpm: 9.5.0 Relevant Packages: next: 15.0.0-canary.68 // Latest available version is detected (15.0.0-canary.68). eslint-config-next: N/A react: 19.0.0-rc.0 react-dom: 19.0.0-rc.0 typescript: 5.3.3 Next.js Config: output: standalone
Which area(s) are affected? (Select all that apply)
Runtime
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
In development (next dev) everything is working fine. Issue seems to be related to the standalone server.
The text was updated successfully, but these errors were encountered: