I am trying to build simple full stack application by using T3 (Next – /pages, tRPC, Prisma, Next-Auth).
Because my application is based on user specific data, I am trying to add user preference page for setting user based UI.
I tried to store the preference data to the backend and fetch it to the client with the SSR rendering method to adjust the UI before they got mounted to prevent flickering Issues and such.
But the problem is, I can’t access the client side object (window, document etc) when they are rendered on the server which means I can’t set CSS classnames to any elements.
After this, I tried different approach with the cookie / local storage but the results are almost same because local storage is also client object and for cookie I can’t set CSS classnames.
If I choose to compromise and use useEffect to wait until the client get hydrated with the JS, I get another issue for flickering UI.
I researched about the problem and found some solutions about the injecting script tag before the client script mounted inside _document.tsx but I am not sure if I can utilize this for setting backgrounds inside Layout components (I am thinking for setting animated lottie-backgrounds).
I am completely lost right now and cannot come up with any kind of ideas.
What approach can I take in this situation?
How can I attach client / backend to generate selectable UI?
Should I just give up this features or take different approach the implement?
Thank you for reading!
Researched hours and hours
Read related docs and blogs