Skip to content

feat: persist editor state using localStorage (offline draft support)#130

Open
amritamishra01 wants to merge 4 commits intolfortran:mainfrom
amritamishra01:feat/localstorage-persistence
Open

feat: persist editor state using localStorage (offline draft support)#130
amritamishra01 wants to merge 4 commits intolfortran:mainfrom
amritamishra01:feat/localstorage-persistence

Conversation

@amritamishra01
Copy link
Contributor

This PR implements automatic persistence of the editor content
using browser localStorage.

Features:

  • Saves editor state locally (debounced 500ms)
  • Restores draft on refresh or browser restart
  • Respects existing URL/Gist priority logic
  • SSR-safe for Next.js
  • Uses versioned storage key (lfortran_user_code_v1)
  • Minimal diff (logic kept inside pages/index.js)

This enables offline draft support without requiring
GitHub login or internet access.
closes #115

@amritamishra01
Copy link
Contributor Author

Hi @certik ,

This is the working video :

pr.130.mp4

The video demonstrates the following scenarios:

Draft Persistence – Editor content is saved automatically (debounced) and restored on refresh.
Hard Refresh Support – Draft persists even after Ctrl + Shift + R.
Browser Restart Recovery – Draft restores after closing and reopening the browser.
URL Override Protection – ?code= parameter loads correctly without overwriting the saved draft.
Priority Restoration – Removing the URL parameter restores the previously saved local draft.
Fallback Behavior – When no draft exists, the default example program loads correctly.

This confirms correct priority handling and offline draft persistence behavior.
Thankyou.

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.

Allow to save/load code in local storage

1 participant