Skip to content

fix: persist user settings across sessions#324

Merged
siddharthvaddem merged 4 commits intosiddharthvaddem:mainfrom
JasonOA888:fix/306-persist-user-settings
Apr 5, 2026
Merged

fix: persist user settings across sessions#324
siddharthvaddem merged 4 commits intosiddharthvaddem:mainfrom
JasonOA888:fix/306-persist-user-settings

Conversation

@JasonOA888
Copy link
Copy Markdown
Contributor

@JasonOA888 JasonOA888 commented Apr 4, 2026

Problem

Settings like padding, aspect ratio, export format, and quality reset to hardcoded defaults when the app restarts (no project loaded). Every new session requires reconfiguring.

Fix

  • Add src/lib/userPreferences.ts with loadUserPreferences()/saveUserPreferences() backed by localStorage
  • Load saved preferences on mount in VideoEditor via useEffect
  • Auto-save when padding, aspectRatio, exportFormat, or exportQuality change
  • Race condition guard with prefsLoadedRef to prevent defaults from overwriting saved prefs

Testing

  1. Open app, change padding to 20%, set format to GIF, quality to source
  2. Close and reopen
  3. Verify settings are preserved

Closes #306

Summary by CodeRabbit

  • New Features

    • Editor settings (padding, aspect ratio, export quality and format) are now persisted and automatically restored across sessions.
  • Bug Fixes

    • Initial preference loading no longer overwrites stored settings; subsequent changes are reliably saved without clobbering restored values.

Add userPreferences module to save/load padding, aspect ratio,
export format and quality to localStorage. Applied on mount
in VideoEditor.

Closes siddharthvaddem#306
Load saved preferences (padding, aspect ratio, export quality, export format)
on mount and auto-save whenever these settings change. Uses the existing
userPreferences.ts utility with a ref guard to prevent overwriting saved prefs
with defaults before the initial load completes.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f1ea5c65-94a4-4abe-afa5-3c730b8de989

📥 Commits

Reviewing files that changed from the base of the PR and between 4f48ecd and a8427b9.

📒 Files selected for processing (2)
  • src/components/video-editor/VideoEditor.tsx
  • src/lib/userPreferences.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/userPreferences.ts

📝 Walkthrough

Walkthrough

VideoEditor now hydrates display/export preferences from persisted storage on mount and persists subsequent changes. A new userPreferences module implements loading, validation, defaults, and saving to localStorage.

Changes

Cohort / File(s) Summary
User Preferences Module
src/lib/userPreferences.ts
Added new module exporting UserPreferences, loadUserPreferences(), and saveUserPreferences(); reads/writes JSON to localStorage, validates fields (padding, aspectRatio, exportQuality, exportFormat), and falls back to DEFAULT_PREFS on errors.
VideoEditor Integration
src/components/video-editor/VideoEditor.tsx
On mount, hydrates editor state (padding, aspectRatio, exportQuality, exportFormat) from loadUserPreferences() and sets prefsHydrated; subsequent changes to those fields are persisted via saveUserPreferences() gated by prefsHydrated to avoid overwriting initial values.

Sequence Diagram(s)

sequenceDiagram
    participant UI as VideoEditor (UI)
    participant Pref as userPreferences module
    participant LS as Browser localStorage

    UI->>Pref: loadUserPreferences()
    Pref->>LS: read PREFS_KEY
    LS-->>Pref: JSON blob / null
    Pref-->>UI: validated UserPreferences
    UI-->>UI: apply to editor state, set prefsHydrated

    Note over UI,Pref: Later, when settings change (padding/aspect/export...)
    UI->>Pref: saveUserPreferences(partial)
    Pref->>LS: read current, merge, write PREFS_KEY
    LS-->>Pref: write ack / error (swallowed)
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code and found a stash,
Of padding, ratios—saved in cache.
On start I fetch, on change I write,
So settings sleep safe through the night.
Carrot-coded memories, snug and bright!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements persistence for padding, aspectRatio, exportFormat, and exportQuality [#306], but does not address automatic timeline aspect ratio matching to monitor on startup. Implement automatic timeline aspect ratio detection and matching to monitor dimensions on startup as required by issue #306.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: persisting user settings across sessions, which is the core objective of the PR.
Description check ✅ Passed The description covers the problem, implementation approach, and testing steps, though it deviates from the template structure by not using the standard sections.
Out of Scope Changes check ✅ Passed All changes are scoped to user preferences persistence via localStorage and VideoEditor integration, directly addressing the linked issue requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d746196d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/video-editor/VideoEditor.tsx`:
- Around line 363-385: The guard currently sets prefsLoadedRef.current = true
synchronously inside the mount useEffect, which allows the autosave useEffect to
run in the same commit with default values; instead, delay flipping
prefsLoadedRef until after the state updates have been committed (e.g., wrap the
assignment in a microtask like queueMicrotask or setTimeout(...,0) inside the
same mount effect) so loadUserPreferences ->
updateState/setExportQuality/setExportFormat run first and only then
prefsLoadedRef is set, preventing saveUserPreferences from persisting defaults;
touch the mount useEffect where prefsLoadedRef, loadUserPreferences,
updateState, setExportQuality and setExportFormat are used.

In `@src/lib/userPreferences.ts`:
- Around line 37-39: The loadUserPreferences function reads
localStorage.getItem(PREFS_KEY) without guarding for storage errors; wrap that
call in a try/catch around the localStorage access (while still using
safeJsonParse on the result) and on any exception fall back to returning {
...DEFAULT_PREFS } so initialization won't throw in
private/disabled/quota-exceeded environments; reference loadUserPreferences,
PREFS_KEY, and safeJsonParse when making the change.
- Around line 47-53: The preference parsing allows invalid values: tighten
validation in the prefs construction where raw.aspectRatio, raw.exportQuality
and raw.exportFormat are read by checking membership against the accepted union
literals instead of broad type checks; for aspectRatio validate raw.aspectRatio
is one of the eight allowed AspectRatio strings before using it (otherwise use
DEFAULT_PREFS.aspectRatio), for exportQuality include "good" (so only "medium" |
"good" | "source" are accepted) and default to DEFAULT_PREFS.exportQuality if
not one of those, and for exportFormat include "mp4" (so only "gif" | "mp4" are
accepted) and default to DEFAULT_PREFS.exportFormat if not one of those.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4da6e219-88be-4cb8-b322-8081464f4e03

📥 Commits

Reviewing files that changed from the base of the PR and between 21893f0 and 7d74619.

📒 Files selected for processing (2)
  • src/components/video-editor/VideoEditor.tsx
  • src/lib/userPreferences.ts

- Replace useRef with useState for prefsHydrated to prevent race condition
- Wrap localStorage.getItem in try/catch in loadUserPreferences
- Validate aspectRatio against known valid values
- Include 'good' in exportQuality validation, 'mp4' in exportFormat validation
- Add updateState to useEffect dependency array
- Remove ineffective biome-ignore suppression comment
- Fix formatting in userPreferences.ts per biome rules
@JasonOA888
Copy link
Copy Markdown
Contributor Author

Pushed fix for CI lint errors:

  1. Added updateState to useEffect dependency array
  2. Removed ineffective biome-ignore suppression comment
  3. Fixed userPreferences.ts formatting per biome rules

CI should pass now.

@siddharthvaddem
Copy link
Copy Markdown
Owner

🙏

@siddharthvaddem siddharthvaddem merged commit f3d761b into siddharthvaddem:main Apr 5, 2026
5 checks passed
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.

[Bug]: not remember settings upon exit

2 participants