Skip to content

fix(react): serialize local storage seed initialization - #407

Open
Egge21M wants to merge 1 commit into
masterfrom
feat/fix-local-storage-seed-race
Open

fix(react): serialize local storage seed initialization#407
Egge21M wants to merge 1 commit into
masterfrom
feat/fix-local-storage-seed-race

Conversation

@Egge21M

@Egge21M Egge21M commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Problem

localStorageSeedGetter() initialized a missing seed with a non-atomic localStorage read-generate-write sequence. Concurrent first-run tabs could each cache a different seed even though only the last seed written remained recoverable from storage.

Summary

  • serialize seed initialization across same-origin browser contexts with an origin-scoped Web Lock
  • fail before generating or writing when Web Locks are unavailable
  • document the secure-context requirement and add a patch changeset
  • add deterministic regression coverage for concurrent initializers and unsupported environments

Verification

  • bun run --filter='@cashu/coco-react' test (50 tests passed)
  • bun run --filter='@cashu/coco-react' typecheck
  • bun run --filter='@cashu/coco-react' lint (passes with two existing warnings)
  • bun run --filter='@cashu/coco-react' build
  • bunx prettier --check packages/react/src/lib/utils/localStorageSeedGetter.ts packages/react/src/lib/utils/localStorageSeedGetter.test.ts packages/react/README.md .changeset/lock-local-storage-seeds.md

This issue was found by Project Loupe

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d687d30

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@cashu/coco-react Patch
@cashu/coco-core Patch
@cashu/coco-indexeddb Patch
@cashu/coco-expo-sqlite Patch
@cashu/coco-sqlite Patch
@cashu/coco-sqlite-bun Patch
@cashu/coco-adapter-tests Patch
@cashu/coco-sql-storage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Egge21M
Egge21M marked this pull request as ready for review July 31, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant