Implement comprehensive fix to ensure worksheet sharing uses the same
persistence/loading logic as user session management.
**Problem:**
- Share save sent unfiltered formState with derived/UI state
- Share load used JSON.parse without validation/migration
- Inconsistent with user session which extracts specific fields and validates
**Solution:**
1. Create extractConfigFields helper (DRY principle)
- Single source of truth for persisted fields
- Excludes derived state (rows, total, date, seed)
- Type-safe extraction of 24 config fields
2. Update useWorksheetAutoSave to use helper
- Replace 50+ lines of manual extraction
- Ensures consistency across all save operations
3. Update all share creation paths
- PreviewCenter: extractConfigFields(formState)
- ActionsSidebar: extractConfigFields(formState)
- ShareModal: extractConfigFields(config)
4. Update share load API to use parseAdditionConfig
- Validates config structure
- Migrates old versions (v1/v2/v3) to v4
- Matches user session loading logic exactly
**Benefits:**
- Consistency: Share and session use identical logic
- Validation: All configs validated before saving/loading
- Migration: Old shared configs auto-migrate to current schema
- Maintainability: 100+ lines reduced to ~30, single source of truth
**Files Changed:**
- utils/extractConfigFields.ts (new helper)
- hooks/useWorksheetAutoSave.ts (refactored to use helper)
- components/PreviewCenter.tsx (use helper)
- components/ActionsSidebar.tsx (use helper)
- components/ShareModal.tsx (use helper + type fix)
- api/worksheets/share/[id]/route.ts (use parseAdditionConfig)
Fixes ensure shared worksheets are persisted and loaded with the same
validation, versioning, and migration as user settings.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>