Open metinvio opened 1 month ago
Hey,
Cookies are a client-only thing, can you try setting the use-client
flag on the files?
Adding 'use client'
at the top of the file should do:
'use client'
import * from ...
Thank you very much for the quick response but can you explain in more detail. I'm new to web dev.🙈
I try to read the cookies in order to conditionally run scripts in _document.js'
element - doesn't _document.js run on server?Sure,
There's 2 reasons:
Why not make it server-side? well....
Some cookies, like we use in the cookiebanner, are strictly a client-side thing so it's impossible to detect this particular type of cookie on the server and pre-render the cookiebanner.
Think of it like this:
If we were to render it on the server side then we'd need to know something about the user to verify who they are, so one could argue we are storing sensitive data (or at least identifiable data, probably even before login).
Lots of extra things to take care off, whilst rendering this one particular component on the client-side doesn't incur much cost at all.
On localhost it just works perfect. This is my cookies component and how i set cookies using react-cookies-consent:
And this is how I read them (nookies.js) after user makes choice and inits a refresh of the page:
Hosting: Vercel Libs: "next": "^14.0.4", "react-cookie-consent": "^9.0.0", "nookies": "^2.5.2",