Client bundle contains unnecessary components with [[...slug]]
catch-all route
#74756
Open
1 task done
Labels
bug
Issue was opened via the bug report template.
Verify canary release
Provide environment information
Which example does this report relate to?
https://github.com/dia-loghmari/next-issue-demo
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
Vercel
Describe the Bug
When using a single
[[...slug]]
catch-all route in thesrc/app
directory, the client bundle contains all imported components, even if they are not used on a specific route.For instance:
/about
uses theCarousel
component./contact
uses theAccordion
component.However, when navigating to
/about
, the client bundle includes JavaScript for bothCarousel
andAccordion
, leading to larger-than-necessary client bundles.Screenshots
System Info
Additional Context
The dynamic imports are wrapped with
dynamic
andssr: true
, but the generated client bundle still includes all unused components. This could indicate that the[[...slug]]
route is not optimized for selective client-side bundling.Expected Behavior
The client bundle for each route should only include JavaScript for the components used on that specific route. For example:
/about
should includeCarousel
only./contact
should includeAccordion
only.To Reproduce
I’ve prepared a minimal reproduction example. Here's the key setup:
src/app/[[...slug]]/page.tsx
.The file that contains the definition of each page.
static/chunk/...js
bundle (as shown in Webpack Bundle Analyzer) contains JavaScript for all components, regardless of the route being accessed.Here is a link to a minimal repository that demonstrates the issue: https://github.com/dia-loghmari/next-issue-demo
The text was updated successfully, but these errors were encountered: