fix(storage): in-memory fallback when browser storage rejects writes (Safari private mode) (#613) - #655
Merged
nonsobethel0-dev merged 2 commits intoSep 24, 2026
Conversation
Safari private browsing (and full/blocked storage) makes localStorage/sessionStorage setItem throw even for tiny writes. The error was caught but the value was dropped, so wallet data and the auth token silently vanished. Keep a per-area in-memory Map: failed writes are stored there, reads fall back to it when browser storage has no value or throws, and removes clear both. Successful writes clear the memory copy so browser storage stays the source of truth. set/setSession still return false when the value wasn't persisted to browser storage, so the API contract is unchanged. Closes Parashield-Protocol#613
Failed localStorage/sessionStorage writes (QuotaExceededError, SecurityError on read and write) stay readable via get/getJSON/getSession, remove clears the fallback, and browser storage wins again once a write succeeds. Refs Parashield-Protocol#613
|
@jakespepe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
❌ Deploy Preview for boisterous-sunshine-dd4c4c failed.
|
nonsobethel0-dev
merged commit Sep 24, 2026
1393eee
into
Parashield-Protocol:main
0 of 4 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Safari private browsing,
localStorage.setItemandsessionStorage.setItemthrow (QuotaExceededError) even for tiny writes. The same happens when storage is full or blocked by site settings.src/lib/storage.tscaught the error but threw the value away, so things like the stored wallet address, network, and the auth token insessionStoragesilently disappeared. The nextgetreturnednull.Fix
In
src/lib/storage.ts:memoryLocal,memorySession).set,setJSON,setSession): if browser storage throws, the value goes into the matching map instead of being lost. A successful write clears any copy in memory, so browser storage stays the source of truth whenever it works.get,getJSON,getSession): if browser storage has no value or throws (Safari can raiseSecurityErroron reads too), the value comes from memory.remove,removeSession): clear both memory and browser storage.setandsetSessionstill returnfalsewhen the value wasn't saved to browser storage, so the existing tests and any callers checking the result behave as before.SecurityErrorwarning is kept.Why memory rather than falling back to
sessionStorage: in Safari private modesessionStoragehas the same write restriction, so memory is the only fallback that always works. The values live only as long as the page, which matches what private browsing should do anyway.This way nothing has to "detect private mode". Browser-sniffing is fragile, and the fallback only kicks in when a write actually fails.
Tests
Added to
src/__tests__/storage.test.ts:localStoragewrite is still readable throughgetandgetJSON, andremoveclears itgetItemandsetItemthrowSecurityError, the value is still readable from memorysessionStoragewrite (such as the auth token) is still readable throughgetSession, andremoveSessionclears itFull suite: 60 failed / 413 passed on this branch vs 61 failed / 408 passed on
main. The failures that were already onmainare unrelated, and this PR adds no new ones.tsc --noEmitreports no errors instorage.ts.Closes #613
Closes #612
Closes #614
Closes #615