Skip to content

Tab State Persistence (localStorage/Tauri) #299

Closed

Description

@malibio

Problem Statement

Tab state (open tabs, active tab, tab order) is lost when the application restarts. Users expect their tab configuration to persist across sessions, similar to how browsers remember open tabs.

Current State

What Exists:

  • ✅ Tab state in memory (navigation.ts store)
  • ✅ Tab creation and management

What's Missing:

  • ❌ Persistence layer for tab state
  • ❌ Loading tab state on application startup
  • ❌ Saving tab state on changes

Proposed Solution

Implement a persistence service that:

  1. Saves tab state to localStorage (or Tauri's store for desktop)
  2. Loads saved state on application mount
  3. Handles migration if tab structure changes
  4. Debounces saves to avoid excessive writes

Main Components Affected

New Files:

  • /packages/desktop-app/src/lib/services/tab-persistence-service.ts - Persistence logic

Modified Files:

  • /packages/desktop-app/src/lib/stores/navigation.ts - Add persistence hooks
  • /packages/desktop-app/src/lib/components/layout/app-shell.svelte - Load state on mount

Implementation Approach

// tab-persistence-service.ts
export interface PersistedTabState {
  version: 1;
  tabs: Array<{
    id: string;
    title: string;
    type: string;
    content: any;
    closeable: boolean;
  }>;
  activeTabId: string;
}

export class TabPersistenceService {
  private static STORAGE_KEY = 'nodespace:tab-state';
  
  static async save(state: TabState): Promise<void> {
    const persisted: PersistedTabState = {
      version: 1,
      tabs: state.tabs,
      activeTabId: state.activeTabId
    };
    
    // Use Tauri store for desktop, localStorage for web
    if (window.__TAURI__) {
      await window.__TAURI__.invoke('save_tab_state', { state: persisted });
    } else {
      localStorage.setItem(this.STORAGE_KEY, JSON.stringify(persisted));
    }
  }
  
  static async load(): Promise<PersistedTabState | null> {
    // Implementation...
  }
}

Acceptance Criteria

  • Tab state persists across application restarts
  • Active tab is restored correctly
  • Tab order is preserved
  • Invalid/corrupted state is handled gracefully (fallback to default)
  • Debounced saves prevent excessive writes (e.g., 500ms debounce)
  • Migration strategy for future tab structure changes

Estimated Effort

3-4 hours

  • Service implementation: 1.5 hours
  • Integration with store: 1 hour
  • Migration and error handling: 1 hour
  • Testing: 30 minutes

Dependencies

Priority

Medium - Nice-to-have UX improvement, not blocking core functionality

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions