Closed cinnamon-bun closed 3 years ago
I think I know what this is: currently we are writing to local storage on every document write. This change to local storage is firing off the hooks which read the storage, causing the app to re-render. For each write there's a re-render, so if you have a workspace like lobbydev.
Is it true that we're only interested in reading from localstorage once, at startup? If so, maybe we don't need the hooks support at all.
If localstorage changes in another tab, we want to re-render this tab. But not if it changes because of something we did in the current tab.
I would assume the useLocalstorage library is smart about this but I might be wrong...
This seems to be fixed in apps like lobby and status!
With 1 workspace, when you reload the page the content appears immediately.
With 2+ workspaces, the Earthbar loads immediately but it sometimes takes a second or two for the content to load from localStorage.
I suspect there's a race condition or something and we're saving-and-loading to localStorage over and over for each document during the boot process? I think I've seen something like this happen also when receiving sync'd changes when there's more than one workspace set up.
Some console.logs around the localStorage code would probably help clear this up