Skip to content

Device: Fix profile editing always opening in create mode#407

Merged
d4rken merged 2 commits intomainfrom
fix/profile-unsaved-changes-false-positive
Feb 24, 2026
Merged

Device: Fix profile editing always opening in create mode#407
d4rken merged 2 commits intomainfrom
fix/profile-unsaved-changes-false-positive

Conversation

@d4rken
Copy link
Copy Markdown
Member

@d4rken d4rken commented Feb 24, 2026

What changed

Fixed device profile editing always opening in create mode instead of edit mode. Also fixed a false "unsaved changes" warning appearing when leaving the profile creation screen without making any edits.

Technical Context

  • Root cause: Navigation 3 does not auto-populate SavedStateHandle from NavKey args, so profileId was always null — every edit opened as a new profile
  • Fix: pass profileId explicitly from the Navigation 3 entry lambda instead of relying on SavedStateHandle
  • Replaced SavedStateHandle-based initialization with an explicit initialize() method to avoid stale state when re-entering the screen
  • Set _initialState to match defaults in create mode so hasUnsavedChanges correctly returns false when nothing was edited
  • Reset initialization flag on every exit path to prevent stale state on re-entry

In create mode, the init block pre-filled _currentState with a default
name but left _initialState empty. The hasUnsavedChanges() check saw
the non-blank name as a change, triggering the dialog on back press
even without user edits.

Set _initialState to match _currentState defaults in create mode and
unify the comparison logic to always use current != initial.
Navigation 3 doesn't auto-populate SavedStateHandle from NavKey args
like Navigation 2.x did. Pass profileId explicitly from the entry
lambda through the ScreenHost to the ViewModel via initialize().

Reset initialized flag on every exit path so re-entering a profile
reloads fresh data from the repository.
@d4rken d4rken added the bug Something isn't working label Feb 24, 2026
@d4rken d4rken merged commit 7e73777 into main Feb 24, 2026
9 checks passed
@d4rken d4rken deleted the fix/profile-unsaved-changes-false-positive branch February 24, 2026 19:38
@d4rken d4rken changed the title fix(profiles): Fix device profile edit screen issues Device: Fix profile editing always opening in create mode Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant