fix(settings): confirm profile-picture upload and refresh the preview (LC-347) #365
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/lc-347-avatar-upload-feedback"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes LC-347.
Problem
Uploading a profile picture at
/settingsgave no signal it worked: no success message, and the avatar preview looked unchanged, so it read as a failure even though the upload succeeded server-side.Root causes (both confirmed in code)
routes::settings::post_profileredirected to/settingsinstead of/settings?saved=1, so the existing "Saved." flash (used bypost_language/post_appearance) never fired.<img src="/avatars/{id}?v={asset_version}">was keyed byasset_version, a build-time constant that never changes on upload, whileroutes::avatar::get_avatarservesCache-Control: max-age=300. The browser kept showing the cached old image for up to five minutes.Fix
post_profileredirects to/settings?saved=1.avatar_cache_keyhelper, surfaced asUserSettingsPage.avatar_version), so the new image loads immediately.Tests
New
server/tests/routes_settings_profile.rs:avatar_upload_redirects_to_saved_flash- POST multipart avatar returns 303 to/settings?saved=1and persistsavatar_ext.settings_avatar_preview_cache_busts_not_asset_version- after upload the rendered<img>is no longer keyed byasset_version(?v=test).just testandjust test-saasboth green.Out of scope (noted in LC-347)
Inline form errors for the wrong-format / over-1-MiB cases (currently a full-page styled error), and the shared static-
asset_versioncache-buster on other avatar render sites (sidebar self, message author rows).Uploading a profile picture gave no signal that it worked: no success message, and the avatar preview appeared unchanged, so it read as a failure even though the upload succeeded. Two causes. First, `post_profile` redirected to `/settings` rather than `/settings?saved=1`, so the existing "Saved." flash (used by `post_language` / `post_appearance`) never fired. Second, the preview `<img src="/avatars/{id}?v={asset_version}">` was keyed by `asset_version`, a build-time constant that never changes on upload, while the avatar route serves `Cache-Control: max-age=300`; the browser therefore showed the cached old image for up to five minutes. `post_profile` now redirects to `/settings?saved=1`, and the preview is cache-busted by the avatar file's mtime (new `avatar_cache_key` helper, surfaced as `UserSettingsPage.avatar_version`) so the new image loads immediately. Adds `routes_settings_profile.rs` covering the `?saved=1` redirect and that the preview URL is no longer keyed by `asset_version`. Out of scope (noted in LC-347): inline form errors for the wrong-format / over-1-MiB cases, and the shared static-`asset_version` cache-buster on other avatar render sites (sidebar self, message rows). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>