Hello Growthbook Team :wave: I have some questions...
# ask-questions
j
Hello Growthbook Team 👋 I have some questions about the Hybrid (SSR + Client-side) approach you're presenting in your documentation. I'll leave them here: 1. Doesn't the
trackingCallback
get called two times? First, when the server prerenders the page, and then on the client side? 2. How is the server supposed to set the
attributes
when it initialize the Growthbook instance inside the
MyPage
component? I mean, in the example you clearly show that you set the
id
property by reading it from the cookies (i.e.,
Cookies.get('my_uuid')
), but when the server prerenders the page doesn't have access to cookies, at least inside the render function. Doesn't this involve a mismatching attribution between client and server, causing hydration errors? Thanks in advance 🙏
s
Hey! 1. The
trackingCallback
may fire twice, but GrowthBook automatically deduplicates these events. 2. With SSR, the idea would be that the server has access to cookies/headers that'd provide the necessary data. With SSR, pages are rendered on demand/dynamically. I understand this to be different than SSG (prerendered pages), where you'd have to rely on client side flags only, as you mentioned. Are you using a specific framework? We have some more in-depth examples for Next.js, for example.
j
> With SSR, the idea would be that the server has access to cookies/headers that'd provide the necessary data. Yes, but not inside a render function (i.e., inside the
MyPage
component where we are instantiating the growthbook instance). This is because inside a render function, the server doesn't have access to the Request object, so it cannot retrieve cookies or headers. And this applies regardless of SSR or SSG. I'm using Nextjs with Pages router btw.
So that's left me wondering whether the attribution can mismatch between client and server, because if the server can't access the cookies inside the component, I don't know what gets passed in the
id
property (when the server performs the prerendering) 🤔
The alternative would be computing the attributes inside
getServerSideProps
or
getStaticProps
and passing them as props, but this defeats the idea behind the hybrid approach. Also, passing attributes as props is not always feasible since sometimes attributes are user-sensitive and they would be serialized and injected inside the HTML of the page..
s
Yep, those are all valid concerns when using Next.js pages. You'll want to determine which tradeoffs work best for your approach. With the question of sensitive attributes, we offer a couple different options: 1) do it only server-side 2) secure attributes and 3) remote evaluation. We also have some more robust next js examples here: https://github.com/growthbook/examples/tree/main/next-js-pages
👍 1