Repository navigation
Keep preferences on iOS: re-link lost device cookies, ship prefs with the page - #420
Merged
Merged
Conversation
… the page iOS WebKit deletes the photomap_device cookie along with localStorage after the browser has been closed for a while. The server then minted a new device with default preferences, orphaning the real record (18 device records in 8 days on one install). On top of that, a boot without localStorage drew the UI from defaults and applied the server copy too late to show, and every write PATCHed the whole settings set, stale values included. - A request without the cookie is re-linked to its device by client IP + User-Agent; a fingerprint belongs to one device at a time, and forget drops it so Reset to Defaults can't resurrect the old record. The cookie is re-sent (renewing Max-Age) on every response. - GET / embeds the device's record as window.initialPreferences and sets the cookie itself; state.js boots from it, falling back to localStorage. reconcileWithServer and the timestamp cache are gone. - Writes send only the keys they changed (persistSettings); the label checkbox, which only ever wrote localStorage, now reaches the server. - page-visibility.js drops the sessionStorage backup and periodic full saves; PATCH uses keepalive so the hide-time flush survives suspension. - Visual session state persists too: whether the UMAP window is open and the last slide shown per album (grid/swiper was already persisted). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes from adversarial review of the previous commit: - A PATCH that fails (network, server restart) is requeued with backoff instead of dropped: with only changed keys sent and the server record winning at boot, a lost write was silently undone on the next reload. A 422 batch is resent key by key so one bad value (e.g. ?delay=5000) doesn't drop the rest. Flushes are serialized. - lastSlideIndex is merged per album, client- and server-side, and each slide change sends only its own album's entry, so two tabs can't overwrite each other's positions. - Reset to Defaults closes the PATCH queue (and waits out one in flight) before the DELETE, so a slideshow tick can't recreate the record. - Fingerprints move only on writes, so two profiles of one browser don't rewrite preferences.json on every request; DELETE no longer re-sends the cookie it clears. - Keys a record lacks but localStorage has are sent up at boot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lstein
added a commit
that referenced
this pull request
Oct 6, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On iOS (Safari, and Chrome/Firefox on iOS), the selected album, slide delay, autotagging flag and control-label visibility reset to defaults after the browser has been closed for a while.
Preferences have been stored on the server since #284, keyed by an HttpOnly
photomap_devicecookie. iOS deletes that cookie along with localStorage, though. The server then created a new device ID with a record of defaults, and the real record was left with nothing pointing to it: one install had 18 device records in 8 days. No client-side storage can fix that.Three more bugs made it worse:
reconcileWithServerapplied the server copy afterwards, but nothing redrew the UI from it.page-visibility.js.Changes
Backend
DELETE /preferences/drops the fingerprint, so Reset to Defaults isn't re-linked.GET /embeds the device's record aswindow.initialPreferences(nullif it has none) and sets the cookie itself. FastAPI doesn't merge a dependency'sResponseinto a response returned directly, hence setting it there. The page is servedCache-Control: no-cache.umapWindowOpen, andlastSlideIndex(album → index, merged per album rather than replaced).Frontend
state.jsstarts from the embedded record, falls back to localStorage, then to defaults.reconcileWithServerand the_prefServerUpdatedAttimestamp cache are gone.persistSettings(...keys), andpersistSlidePosition.keepalive;page-visibility.jsdrops the sessionStorage backup/restore and the periodic full saves.Known limits
Testing
make lint, Jest (997 tests) and pytest (1299 tests) all pass. New tests cover:🤖 Generated with Claude Code