react-tracking icon indicating copy to clipboard operation
react-tracking copied to clipboard

Question: How to integrate with NextJS (server-side components)

Open alexdelgado opened this issue 2 years ago • 2 comments

Hey!

It looks like you're creating a client-side context which works great in most cases, but NextJS does a lot of server-side rendering and caching so either you push <track /> really far down, or lose out on some of NextJS's caching.

Is that right?

How are you integrating the two?

alexdelgado avatar Feb 01 '24 19:02 alexdelgado

Alex, Have you had any success with Nextjs 14 and this package since this creating this issue?

visualjeff avatar Mar 07 '24 20:03 visualjeff

Nope, we ended up building our own data layer that doesn't use react contexts. While most of the data layer does work "client side", we're still leveraging server-side rendering using the Script tag with onReady functions.

alexdelgado avatar Mar 07 '24 21:03 alexdelgado

So most everything happens within a useEffect and the context should be getting re-established client-side so the server-side ends up being mostly a no-op.

We used this with a server-rendered framework at NYT, so it should work fine in an SSR mode.

What issues were you running into @alexdelgado ?

tizmagik avatar May 26 '24 12:05 tizmagik

Honestly it turned out to be a mis-understanding of how inter-leaving works in Next.js I was under the impression that if you created a client-side context then everything would become client-side. It took watching some videos to understand that's not the case.

alexdelgado avatar May 28 '24 16:05 alexdelgado