about summary refs log tree commit diff
path: root/src/lib/api/feed-manip.ts
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-08-06 01:03:27 +0100
committerGitHub <noreply@github.com>2024-08-06 01:03:27 +0100
commit966f6c511fff510fc011aa5c426c6b7eaf4f21ac (patch)
treef42acd179b6cf1421fcf1a5a4e55c5390206113b /src/lib/api/feed-manip.ts
parent5bf7f3769d005e7e606e4b10327eb7467f59f0aa (diff)
downloadvoidsky-966f6c511fff510fc011aa5c426c6b7eaf4f21ac.tar.zst
[Persisted] Fix the race condition causing clobbered writes between tabs (#4873)
* Broadcast the update in the same tick

The motivation for the original code is unclear. I was not able to reproduce the described behavior and have not seen it mentioned on the web. I'll assume that this was a misunderstanding.

* Remove defensive programming

The only places in this code that we can expect to throw are schema.parse(), JSON.parse(), JSON.stringify(), and localStorage.getItem/setItem/removeItem. Let's push try/catch'es where we expect them to be necessary.

* Don't write or clobber defaults

Writing defaults to local storage is unnecessary. We would write them as a part of next update anyway. So I'm removing that to reduce the number of moving pieces.

However, we do need to be wary of _state being set to defaults. Because _state gets mutated on write. We don't want to mutate the defaults object. To avoid having to think about this, let's copy on write. We don't write to this object very often.

* Refactor: extract tryParse

* Refactor: move string parsing into tryParse

* Extract tryStringify, split logging by platform

Shared data parsing/stringification errors are always logged. Storage errors are only logged on native because we trust the web APIs to work.

* Add a layer of caching to readFromStorage to web

We're going to be doing a read on every write so let's add a fast path that avoids parsing and validating.

* Fix the race condition causing clobbered writes between tabs
Diffstat (limited to 'src/lib/api/feed-manip.ts')
0 files changed, 0 insertions, 0 deletions