-
Notifications
You must be signed in to change notification settings - Fork 0
馃Ч Implement LocalStorage Fallback for Sync Failure #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -475,7 +475,7 @@ async function executeBatchPayload() { | |||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||
| console.error("Critical Sync Failure:", error); | ||||||||||||||||||||||||||||||||
| DOM.syncStatus.innerHTML = `<span style="color:#ff453a">鈿狅笍 Sync Failed. Error: ${error.code || 'Network'}</span>`; | ||||||||||||||||||||||||||||||||
| // Potential fallback: Save to localStorage for later recovery | ||||||||||||||||||||||||||||||||
| localStorage.setItem('failed_sync', JSON.stringify(STATE.results)); | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using a fixed key ( Useful? React with 馃憤聽/ 馃憥. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 馃憤聽/ 馃憥.
|
||||||||||||||||||||||||||||||||
| localStorage.setItem('failed_sync', JSON.stringify(STATE.results)); | |
| // Best-effort local persistence of failed sync; avoid masking original error | |
| if (typeof localStorage !== 'undefined') { | |
| try { | |
| localStorage.setItem('failed_sync', JSON.stringify(STATE.results)); | |
| } catch (storageError) { | |
| console.error("Secondary failure: unable to persist failed sync to localStorage:", storageError); | |
| } | |
| } else { | |
| console.warn("localStorage is not available; failed sync data was not persisted locally."); | |
| } |
Copilot
AI
Mar 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a single fixed key (failed_sync) will overwrite any prior failed payloads (including retries or multiple participants on the same device). Consider namespacing the key with STATE.pid and/or a timestamp, and consider clearing the stored payload after a successful sync so the browser doesn鈥檛 retain stale telemetry indefinitely.
Copilot
AI
Mar 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This persists STATE.results (including free-form semantic_justification) to localStorage, which is long-lived and readable by any JS running on this origin (increasing impact of any future XSS). If persistence is required, consider storing the minimum necessary fields and/or using sessionStorage with an explicit user download/export flow, and document/communicate the retention/cleanup behavior.
| localStorage.setItem('failed_sync', JSON.stringify(STATE.results)); | |
| // Persist a reduced, session-scoped payload without free-form justification | |
| const failedSyncPayload = STATE.results.map(({ semantic_justification, ...rest }) => rest); | |
| sessionStorage.setItem('failed_sync', JSON.stringify(failedSyncPayload)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation risks data loss by overwriting previously saved failed syncs. If a user has a failed sync, and then runs another session that also fails to sync, the data from the first session will be lost. The data should be appended to any existing failed sync data.
Additionally,
localStorage.setItemcan fail if storage is full or disabled. It's crucial to wrap this in atry...catchblock to handle such errors gracefully, especially since this is a data safety feature. My suggestion includes this, along with a user-facing message for this failure case.