Skip to content

Autosave edits and new pages as local drafts - #9

Merged
codeling merged 3 commits into
mainfrom
claude/wonderful-mayer-6houpq
Oct 2, 2026
Merged

codeling merged 3 commits into
mainfrom
claude/wonderful-mayer-6houpq

Conversation

@codeling

Copy link
Copy Markdown
Owner

Summary

Mobile browsers unload tabs that are left inactive, and any text in the edit field that hadn't been saved was lost. With this change, the edit form's content is kept as a draft in the browser's localStorage and restored when the page is opened again.

  • The text, title and commit message are saved on every change and when the page gets hidden (visibilitychange / pagehide).
  • When the edit or new page is opened again, the draft is restored and a note is shown. The note says when the draft was saved and has a Discard draft button.
  • If the page was changed on the server after the draft was started, the note also shows a warning.
  • The draft is removed on Save and on Cancel. It is also removed silently if it matches the server content.
  • The draft key includes the script path and the page name (for new pages, the title the form opened with), so drafts for different pages and wiki instances stay separate.
  • Nothing is written to the server until Save, so autosave creates no git commits.
  • wiki.js and the Markdown formatting helper are now also loaded for new pages. Before, only edit pages loaded them, so new pages also get the "unsaved changes" warning when leaving.
  • The new strings are added to the de and en locale files.

Testing

Checked in headless Chromium against php -S:

  • An edit draft is restored after a reload.
  • Discard draft brings back the original text and removes the draft.
  • A new page's draft (title + text) is restored.
  • Saving removes the draft.
  • The conflict warning appears when the page was changed on disk after the draft was started.

🤖 Generated with Claude Code

https://claude.ai/code/session_01R83ERf8xo5QNNs6vp9v7at


Generated by Claude Code

The content of the edit form (text, title, commit message) is stored in
localStorage on every change and when the page gets hidden, and restored
when the edit/new page is loaded again. This prevents losing edits when a
(mobile) browser unloads an inactive tab. A note with a "Discard draft"
button is shown on restore, including a warning if the page was changed
in the meantime. Drafts are removed on save and cancel.

wiki.js and the formatting helper are now also loaded for new pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R83ERf8xo5QNNs6vp9v7at
Conflicts: index.php (use isEditorAction(), keep main's form action and
CSRF field, add the draft data attributes) and wiki.js (keep the draft
handling, which also covers title input and clears the draft on submit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R83ERf8xo5QNNs6vp9v7at
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R83ERf8xo5QNNs6vp9v7at
@codeling
codeling merged commit 6a76bd9 into main Oct 2, 2026
15 checks passed
@codeling
codeling deleted the claude/wonderful-mayer-6houpq branch October 2, 2026 21:36
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.

2 participants