Skip to content

🐛 Fix lost writes and failed loads in the storage adapters - #245

Merged
mbret merged 2 commits into
mainfrom
claude/awesome-bell-2a040j
Nov 3, 2026
Merged

mbret merged 2 commits into
mainfrom
claude/awesome-bell-2a040j

Conversation

@mbret

@mbret mbret commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Why

With createLocalStorageAdapter({ key }), two persisted signals that change in the same handler keep only the last write. The other value is lost without an error.

A stored value that is not JSON stops the hydration at every load. isHydrated stays false, and nothing is persisted after that.

  • Change: the shared entry is read and written with no await in between.
  • Change: both adapters read a value that is not JSON as nothing stored.
  • Gain: overlapping writes are all saved, and a value that is not JSON no longer blocks the app.

What's new

Other changes

  • ✅ Tests for both adapters, which had none

Details

  • A shared entry that is not JSON counts as an empty store, so the next write replaces it.
  • The shared store's getItem uses Object.hasOwn, so a key such as constructor no longer returns a function from the object's prototype.
  • Two tabs can still overwrite each other's shared entry, because localStorage has no lock across tabs.

🔍 Self-reviewed with selfcorrect-review
🤖 Made within harness coverage


Generated by Claude Code

`JSON.parse` threw in the `getItem` of both adapters, and
`persistSignals` then stopped the entry. So `isHydrated` stayed `false`
and the signal was never persisted again. The bad value stayed in
storage, and every reload stopped at the same point.

Both adapters now read such a value as `undefined`, which the hydration
already treats as "nothing stored".

Closes #236.

Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
`createLocalStorageAdapter({ key })` keeps all signals in one entry.
Each call read the entry, waited, then wrote a changed copy. A second
call read the same old entry during that wait, so the last write won.
Two persisted signals that changed in the same handler lost one value.

Each call now reads and writes the entry synchronously, with no
`await` in between.

Closes #233.

Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
@mbret mbret self-assigned this Nov 3, 2026
@mbret
mbret marked this pull request as ready for review November 3, 2026 23:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T23:27:13.027492Z d74b133 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mbret
mbret merged commit 78267d8 into main Nov 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persistence: a stored value that is not JSON blocks hydration forever createLocalStorageAdapter({ key }): overlapping writes lose updates

2 participants