Persistence limits, recovery and offline design
Quick answer
Browser persistence is not a permanent backup. IndexedDB data can be unavailable, evicted, cleared or incompatible with newer application schemas. Design explicit recovery and validation paths.
How it works
Handle open, upgrade, request and transaction failures. Store a versioned data contract and validate restored values before using them. When a local copy is missing, distinguish first-use state from an error; never claim synchronization succeeded before the remote system confirms it. Do not keep secrets in browser storage as a security boundary. Examples exercise deterministic restore policy, not actual storage quota or eviction.
Local examples
Run in a fresh browser document; no external network is needed. The actual ByteMind editor is unverified.
(async () => {function restore(x){if(x===undefined)return "missing";return x&&x.version===1&&typeof x.text==="string"?"valid":"invalid";}console.log(restore(undefined),restore({version:2,text:"x"}),restore({version:1,text:"x"}));})()Expected console output:
missing invalid validMissing and incompatible records remain distinct.
Run in a fresh browser document; no external network is needed. The actual ByteMind editor is unverified.
(async () => {const state={localSaved:true,remoteConfirmed:false};console.log(state.localSaved&&!state.remoteConfirmed?"pending-sync":"synced");})()Expected console output:
pending-syncLocal success does not establish remote success.
Common mistakes
Do not silently treat a failed read as an empty successful database or promise offline edits are synchronized.
Guided practice
Design a versioned offline draft record, with distinct missing, invalid and valid restoration outcomes.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Persistence limits, recovery and offline design — Knowledge Check
Apply the concept and reason about the example output.
Does IndexedDB guarantee permanent retention?
When should the interface claim a remote write synchronized?
Why validate a restored record?
What is the expected console output of Persistence limits, recovery and offline design example 1?
(async () => {function restore(x){if(x===undefined)return "missing";return x&&x.version===1&&typeof x.text==="string"?"valid":"invalid";}console.log(restore(undefined),restore({version:2,text:"x"}),restore({version:1,text:"x"}));})()What is the expected console output of Persistence limits, recovery and offline design example 2?
(async () => {const state={localSaved:true,remoteConfirmed:false};console.log(state.localSaved&&!state.remoteConfirmed?"pending-sync":"synced");})()