added some error handling

This commit is contained in:
authentik Default Admin 2026-03-04 18:55:48 -08:00
parent 8b6f09cead
commit c25700d7cd
4 changed files with 154 additions and 29 deletions

View file

@ -2,34 +2,35 @@
## 1. Critical Issues
- [ ] **1.1 Fix missing `del` import in store/index.js**
- Line 3 imports `get, set` from idb-keyval but `del` is used on line 13
- Add `del` to the import statement
- This will cause a ReferenceError when removeItem is called
- [x] **1.1 Fix missing `del` import in store/index.js** ✅ COMPLETE
- Line 3 now imports `get, set, del` from idb-keyval
- Used in removeItem function on line 13
- No more ReferenceError
- [ ] **1.2 Fix hydration flag initialization**
- The `onRehydrateStorage` callback uses `store.setState()` before `store` is fully initialized
- Creates a circular reference issue preventing app from loading
- **Options:**
- A) Initialize `_hydrated: true` by default (simplest)
- B) Use Zustand's persist middleware built-in hydration detection
- C) Move hydration callback outside store creation
- [x] **1.2 Fix hydration flag initialization** ✅ COMPLETE
- Implemented Option A: Initialize `_hydrated: true` by default
- Removed problematic `onRehydrateStorage` callback
- App now loads immediately without hanging on "loading..."
- Persistence happens in background automatically
- [ ] **1.3 Consolidate duplicate storage implementation**
- Storage is defined in both `store/index.js` AND `store/middleware/persistence.js`
- The middleware file exports `idbStorage` but it's not being used
- **Decision needed:** Use one or the other, not both
- [x] **1.3 Consolidate duplicate storage implementation** ✅ COMPLETE
- Single storage implementation in `store/index.js`
- Uses idb-keyval directly with createJSONStorage
- Clean, simple approach without extra middleware files
## 2. Architectural Improvements
- [ ] **2.1 Add error handling**
- Add try/catch blocks around IndexedDB operations
- Implement fallback if IndexedDB fails or is unavailable
- Add user feedback for errors (toast notifications?)
- [x] **2.1 Add error handling** ✅ COMPLETE
- Added try/catch blocks around all IndexedDB operations (getItem, setItem, removeItem)
- Implemented fallback: returns null on getItem error, silently fails on setItem/removeItem
- Added error state to store with auto-clear after 3 seconds
- Added validation in addItem and removeItem actions
- Created error-toast component with slide-in animation
- Toast shows error messages and allows manual dismissal
- [ ] **2.2 Add partialize option to persist middleware**
- Currently saves ALL state including `_hydrated` flag and `route`
- Should use `partialize: (state) => ({ user: state.user, items: state.items })`
- [x] **2.2 Add partialize option to persist middleware** ✅ COMPLETE
- Added partialize to exclude `_hydrated` flag from persistence
- Only persists: user, items, and route
- Prevents unnecessary data in IndexedDB
- [ ] **2.3 Add basic CSS reset to index.html**