Skip to content

fix(admin): keep an unsaved New connections choice across the 2-second refresh - #266

Open
kris-anderson wants to merge 2 commits into
Python-roborock:mainfrom
kris-anderson:fix/admin-new-connections-toggle
Open

kris-anderson wants to merge 2 commits into
Python-roborock:mainfrom
kris-anderson:fix/admin-new-connections-toggle

Conversation

@kris-anderson

@kris-anderson kris-anderson commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #265

The dashboard refreshes every 2 seconds, and renderAuth() set the New connections checkbox to the saved value each time, so a tick or untick was undone before Save could be pressed.

Change

  • A change on the checkbox marks it edited and shows "Unsaved change: press Save to apply it."
  • While it's edited, renderAuth() leaves the checkbox and that line alone. The rest of the auth panel still refreshes.
  • Save clears the flag and renders the server's answer, so the page follows the saved state again. It clears the flag only when the box still matches the value the server stored, so a change made while Save is in flight stays unsaved (from the review).

Testing

  • uv run pytest tests/test_admin_api.py: 26 passed.
  • In a browser, against a local instance built from the test config in tests/conftest.py with the lifespan off:
    • On main: I ticked the box and waited 3 seconds, and it was unticked again.
    • With this change:
      • a tick stays through 7 seconds of refreshes, with the unsaved note;
      • Save stores it (/admin/api/auth returns new_connections_enabled: true);
      • unticking and saving stores false;
      • with no local edit, a change saved from another client still shows within one refresh.
      • with the Save reply delayed by 2 seconds, tick → Save → untick before the reply leaves the box unticked with the unsaved note while the server holds the first save, and a second Save stores false.

🤖 Generated with Claude Code

…d refresh

The dashboard refreshes every 2 seconds and renderAuth() set the New
connections checkbox to the saved value each time, so a tick or untick was
undone before Save could be pressed.

A change on the checkbox now marks it edited and shows "Unsaved change: press
Save to apply it."; renderAuth() leaves the checkbox and that line alone until
Save, which clears the flag and renders the server's answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 01:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A pending Save response can overwrite a newer checkbox edit and clear its unsaved notice, causing an unsaved choice to be lost.

1 open issue
What changed in this PR

Addresses #265 by preserving an unsaved “New connections” choice during the admin dashboard’s two-second refresh.

Changes:

  • Tracks checkbox edits and displays an unsaved-change notice.
  • Preserves the edited choice and notice while the rest of the auth panel refreshes.
  • Clears the edit flag after a successful Save and renders the server response.
File Description
src/​roborock_local_server/​standalone_admin.py Adds edit-state tracking and refresh protection for the New connections checkbox.

Review effort: Balanced

new_connections_enabled: document.getElementById("newConnectionsEnabled").checked
}})
}});
connectionsEdited = false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in e4e943e. The flag is now cleared only when the box still matches the value the server stored, so a change made while Save is in flight stays unsaved.

I checked it in a browser with the Save reply delayed by 2 seconds:

  • tick → Save → untick before the reply: the box stays unticked with the unsaved note, and the server holds the first save;
  • a second Save stores false.

The admin tests still pass (26).

Save cleared the edited flag unconditionally, so tick, Save, then untick
before the reply ended with the box ticked and the unsaved note gone. The flag
is now cleared only when the box still matches the value the server stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Admin page: the New connections checkbox reverts within 2 seconds unless Save is pressed right away

2 participants