https://www.growthbook.io/ logo
v

victorious-library-28522

03/10/2023, 9:07 AM
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

fresh-football-47124

03/10/2023, 9:09 AM
We have some examples on how to use Nextjs
there is a NextJS directory that has examples for SSR, Middleware, and client side
v

victorious-library-28522

03/10/2023, 9:55 AM
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

numerous-ambulance-47156

03/10/2023, 2:25 PM
@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

future-teacher-7046

03/10/2023, 11:11 PM
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

victorious-library-28522

03/13/2023, 5:10 AM
@numerous-ambulance-47156 were you able to make it work?
n

numerous-ambulance-47156

03/13/2023, 8:50 AM
@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
3 Views