Next.js Discord

Discord Forum

What is the best approach for consistent data that should be accessible mostly on the client side?

Unanswered
Savannah posted this in #help-forum
Open in Discord
SavannahOP
Fully describe what you're trying to accomplish:
I often want an update in one tab to occur across all tabs, without using firebase/supabase real time databases etc. For example, UI preferences, or the users data for some long-session work (like a name of a currently "in focus" project)

Include the relevant chunks of code in your post:
Right now I am using mobx and IndexDB in the browser to serialise it but this feels very wrong. I don't know how, but Mobx on an old React project from 2017 has always persisted across tabs by default, but it's not happening with next (for serverActions this makes sense, but for the client it's because it's initialised each page load due to how next.js works vs react with its SPA (although I still am confused how mobx on the old react code syncronises changes across all tabs immediately - is this unusual? I thought it was default)

Include the logs/errors you are receiving:
The pattern of serializing mobx feels wrong.

Explain what you've tried to solve the issue:
Looked at mobx-persistent-state, some mobx nextjs libraries, but still overall confused about the right pattern for storing data that spans clientside tabs/sessions and sometimes server contact too.

For example: the user provides the url of their website for our serverAction web crawler to crawl and grab their logo to help them set up their profile.
This url to their site will be used over and over during the session but is not going to be in the DB since they do it for lets say different sites each time. The server should be able to access it for this client session (like PHP $SESSION back in the day) and it should be able to be stored across all tabs on the client.

Example 2: The user sets dark mode, we want to store this preference and repopulate it on tab reload without using supabase/firebase etc.

Any ideas on a better pattern/approach? What am I missing?

0 Replies