Hi, I am currently integrating growthbook to NextJ...
# announcements
v
Hi, I am currently integrating growthbook to NextJS application. I can not make use of the SSR to load the GB features as the SSR response is being cached. Is there a work around to load the features quicker?
f
We have some examples on how to use Nextjs
there is a NextJS directory that has examples for SSR, Middleware, and client side
v
The issue is that i can not set the attributes from server side, (as they are being set here in
getServerSideGrowthBookContext
): Is there a way of setting the attributes from client side but loading the features on server?
n
@victorious-library-28522 I did face with the same issue and ended up moving entire logic to backend
Somehow Growthbook is not able to set attributes on client side and
trackingCallback
is never triggered
f
If you can get the back end to include the features JSON object in the SSR response, you can pass that directly into the client side SDK instance when you instantiate it.
đź‘Ť 1
v
@numerous-ambulance-47156 were you able to make it work?
n
@future-teacher-7046 We believe that the source of the problem is transpilation process of NextJS. please take a look at these code excerpts. imagine we have 2 variations, so
weights
(
n
) is
[0.5, 0.5]
. could you spot the issue? code sample 1: (Growthbook source code)
Copy code
// const weights = [0.5, 0.5];
// const coverage = 1;
let cumulative = 0;
return weights.map((weight) => {
  const start = cumulative;
  cumulative += weight;
  return [start, start + coverage * weight];
});
code sample 2: (Transpiled code after
next build
)
Copy code
// const n = [0.5, 0.5];
// const t = 1;
let a=0;
return n.map(e=>[a+=e,a+t*e])
@victorious-library-28522 We couldn’t solve the transiplation issue above but we solved the issue via using SSR instead of CSR
next version: 12.3.1