Best practice for using providers with server components
Unanswered
Sun bear posted this in #help-forum
Sun bearOP
The NextJS docs for server + client components say that a provider should be placed as deep as possible in the tree, to allow more things to be server components before encountering a client boundary:
https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers
What I'm wondering though, is how you can effectively put the provider "as deep as possible" if a typical server component rendering tree would look like a bunch of server component branches with client component "leaves" at the ends. If we assume all those client components need this provider, wouldn't we need to put the provider at some point in the tree that's above every branch containing a client component?
It seems like a better way would be to ensure that the same provider is copied and pasted to the beginning of each "client component" tree, but that seems really janky.
https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers
What I'm wondering though, is how you can effectively put the provider "as deep as possible" if a typical server component rendering tree would look like a bunch of server component branches with client component "leaves" at the ends. If we assume all those client components need this provider, wouldn't we need to put the provider at some point in the tree that's above every branch containing a client component?
It seems like a better way would be to ensure that the same provider is copied and pasted to the beginning of each "client component" tree, but that seems really janky.