Am I misunderstanding RSC client bundle?
Answered
Rough harvester ant posted this in #help-forum
Rough harvester antOP
First, the setup. VariantA and VariantB are both client components with 'use client' and useState.
I was always under the impression that if VariantA is selected, VariantB’s bundle won’t make it to the browser. Until I got curious and tested it myself. Turns out that’s not the case. The
Am I misunderstanding something? I thought one of the draws of RSC is that the client bundle can be optimized according to just what the user needs.
import { VariantA } from './VariantA'
import { VariantB } from './VariantB'
export default function Page() {
const random = Math.random()
const variant = random < 0.5 ? 'A' : 'B'
return <main>{variant === 'A' ? <VariantA /> : <VariantB />}</main>
}I was always under the impression that if VariantA is selected, VariantB’s bundle won’t make it to the browser. Until I got curious and tested it myself. Turns out that’s not the case. The
http://localhost:3000/_next/static/chunks/app/path-to-page/page-d7bdefff71ae8536.js JS consists of both A and B.Am I misunderstanding something? I thought one of the draws of RSC is that the client bundle can be optimized according to just what the user needs.
4 Replies
Rough harvester antOP
I guess that makes sense, otherwise Next has to create the chunk on-the-fly. thanks @Ray
@Rough harvester ant I guess that makes sense, otherwise Next has to create the chunk on-the-fly. thanks <@743561772069421169>
please mark solution if you problem has been solved