NUCLEAR RESET FIX
Documentation for Plans
Nuclear Reset Fix: Marker-Based Two-Phase Reset
๐ The Problem
The nuclear reset button was clearing all storage successfully but data was mysteriously reappearing after page reload!
Root Cause Analysis (Multiple Issues Found)
The logs revealed a critical race condition:
โ
All IndexedDB databases deleted
โ
Nuclear reset complete! Forcing hard reload...
โก [BEFOREUNLOAD] Attempting to flush pending persistence... โ ๏ธ <- CULPRIT!
What was happening:
- Nuclear reset deletes all IndexedDB databases โ
- Nuclear reset triggers redirect to
/landing - Browser fires
beforeunloadevent before navigation - App's
beforeunloadhandler flushes in-memory state back to storage ๐ฅ - Deleted universes get re-saved from memory!
- Page reloads with "deleted" data magically restored
Why Delete Button Worked
The individual delete button worked perfectly because:
- It doesn't trigger page reload
- No
beforeunloadevent fires - Memory and storage updates happen together
- No race condition
โ The Solution
1. Added Disable Flag to AppComponent
// โข๏ธ Flag to disable persistence flush during nuclear reset
private static disableFlushOnUnload = false;
/**
* โข๏ธ PUBLIC API: Disable flush on unload (for nuclear reset)
*/
public static disablePersistenceFlush(): void {
AppComponent.disableFlushOnUnload = true;
console.log('โข๏ธ [AppComponent] Persistence flush DISABLED for nuclear reset');
}
2. Modified beforeunload Handler
private handleBeforeUnload = () => {
// โข๏ธ CRITICAL: Skip flush if nuclear reset is in progress
if (AppComponent.disableFlushOnUnload) {
console.log('โข๏ธ [BEFOREUNLOAD] Flush DISABLED for nuclear reset - data will not be re-saved');
return;
}
console.log('โก [BEFOREUNLOAD] Attempting to flush pending persistence...');
this.flashHydrator.flushPendingPersistence().catch(error => {
console.error('โก [BEFOREUNLOAD] Flush failed:', error);
});
};
3. Modified Visibility Change Handler
Also protected the visibility change handler (fires when user switches tabs):
private handleVisibilityChange = async () => {
if (document.hidden) {
// โข๏ธ CRITICAL: Skip flush if nuclear reset is in progress
if (AppComponent.disableFlushOnUnload) {
console.log('โข๏ธ [VISIBILITY] Flush DISABLED for nuclear reset - data will not be re-saved');
return;
}
// ... flush logic
}
};
4. Updated Nuclear Reset Flow
Added Step 0 to disable flush before clearing data:
async nuclearReset(): Promise<void> {
try {
// 0. โข๏ธ CRITICAL: Disable beforeunload flush to prevent data from being re-saved
console.log('๐งน Step 0: Disabling persistence flush on page unload...');
(await import('../../../app.component')).AppComponent.disablePersistenceFlush();
console.log('โ
Persistence flush disabled');
// 1-10. Continue with clearing process...
// ...
}
}
๐ฏ Expected Results
With this fix, the nuclear reset should now:
- โ Disable persistence flush before clearing data
- โ Clear user context, guest sessions, Flash Persistence
- โ Clear space/universe data and sync queue
- โ Nuclear cache reset (micro-cache + boot manifests)
- โ Clear localStorage and sessionStorage
- โ
Delete ALL IndexedDB databases with proper
await - โ
Redirect to
/landing - โ
beforeunloadevent fires but SKIPS flush ๐ - โ Page reloads with completely clean state
๐ Console Logs to Verify
On the next nuclear reset attempt, you should see:
โข๏ธ NUCLEAR RESET INITIATED
๐งน Step 0: Disabling persistence flush on page unload...
โข๏ธ [AppComponent] Persistence flush DISABLED for nuclear reset
โ
Persistence flush disabled
๐งน Step 1: Clearing user context...
...
โ
All IndexedDB databases deleted
โข๏ธ [BEFOREUNLOAD] Flush DISABLED for nuclear reset - data will not be re-saved โ
<- SUCCESS!
๐๏ธ Architecture Impact
This fix demonstrates an important consideration for offline-first architectures:
- Automatic persistence is powerful but must respect destructive operations
- Race conditions can occur between storage clearing and automatic flushes
- Explicit control flags are needed for special cases like nuclear resets
- All persistence points (beforeunload, visibilitychange) need protection
๐ Related Files
apps/gograb-space/src/app/app.component.ts- Added disable flag and protected flush handlersapps/gograb-space/src/app/components/space-components/g-space-dashboard/g-space-dashboard.component.ts- Updated nuclear reset to disable flush
๐งช Testing Verification
To test:
- Create test universes
- Click nuclear reset button (โข๏ธ)
- Confirm both warnings
- Watch console logs
- After redirect, verify NO universes exist
- Check IndexedDB in DevTools โ Should be empty or new DB
Status: โ
Implemented
Impact: Critical - Ensures nuclear reset actually works
Performance: None - Only affects nuclear reset flow