-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Client bundle contains unnecessary components with [[...slug]]
catch-all route
#74756
Comments
Hello, I got this response from Customer Success Engineer at Vercel:
Thank you team for this response. It may help some users here. That means you can add use client to the component mapping: // componentMap.tsx
"use client"; // <- here
import dynamic from "next/dynamic";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const componentMap: Record<string, React.ComponentType<any>> = {
Header: dynamic(() => import("../components/Header"), { ssr: true }),
Carousel: dynamic(() => import("../components/Carousel"), { ssr: true }),
Accordion: dynamic(() => import("../components/AccordionDemo"), {
ssr: true,
}),
}; or you can you can add Unfortunately, this only applies to client routes. It doesn't work with RSC components. I mean, it's not possible to nest client and server components in the tree. 😥 To illustrate two use cases that limit us, I've created this sample on github. With a RSC component (the Accordion) In the first I added First use case: https://github.com/dia-loghmari/next-issue-demo/tree/feature/client-page Please see the readme.md. |
Here is a similar issue, linking for reference: #69865 |
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: