fix(connection-form): a new edit target withdraws the dialog's transients (#1180) - #1205
Conversation
…ents (libredb#1180) A host of the published `ConnectionModal` can replace `editConnection` while `isOpen` stays true, because the close path is not the only way the dialog can stop being about one connection. Applying a new target cleared none of the four transient values, so the previous target's degraded-save acknowledgement carried over: the next connection was handed to `onConnect` on its FIRST click, having reported nothing, and the previous target's "click again" banner was shown over it. The close path already cleared all four. The two lists are now one function called from both, because two copies of that list had already drifted once - which is the bug - and would be free to drift again. The trigger is the block's existing one, unchanged: a rerender carrying the same target is not a new connection, so it must not ask again, or the second click becomes unreachable for every host that re-renders while the dialog is open. The second test pins that side, because a fix that withdrew on every render would pass the first test alone. The comment above the degraded branch said the dialog closing is the only thing that withdraws the acknowledgement, which is what the code was believed to do and no longer is. It now names the two triggers this hook owns and points at libredb#1167 for the third. Not the save path: libredb#1167 owns withdrawing the acknowledgement after a successful save, and both PRs change this file, so this branches from main and will need a rebase if either lands first.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…cknowledgement (libredb#1180) The comment said a successful save withdraws it too, which no code path does yet: that is libredb#1167's work. It now names the two triggers this hook has.
|
Thanks @methakon, this is what #1180 asked for. On main the new-target test fails on I pushed 8b101cf, a comment-only change: the note above the degraded branch said a successful save also withdraws the acknowledgement, but no code path does that yet; that is #1167's work. It now names only the two triggers this hook has. |
|
@cevheri this one is ready too. 22 passed, 2 skipped, E2E included. One thing to flag rather than have you find: the issue asked for a branch from The part worth a second look is the trigger. I kept the block's existing |
|
Thank you, and you are right on I wrote "A successful save withdraws it as well (#1167)" on the assumption #1167 had already landed. It has not: it is still open, so no code path does that, and a comment asserting a behaviour the hook does not have is worse than no comment. Naming only the two triggers the hook actually owns is the correct version, and I should have written that from the code rather than from what I expected to be true elsewhere in the tree. Thank you also for confirming the two tests behave as intended - the new-target one failing on main and passing here, and the same-target one holding on both. That second test is the one I would have been most tempted to drop as redundant, and it is exactly what stopped a fix that withdrew on every render. My ping landed after you had already merged, which wasted your time on a status update you did not need. Noted for next time: check whether the PR has moved before reporting on it. |
…a new edit target (#1157) Applying a new edit target now resets every connection-scoped field to its default before the target's own values go in, through one `resetConnectionFields` helper that the close path calls too. A field the target does not carry, such as a tunnel, TLS, `serviceName`, `instanceName` or the Mongo URI mode, no longer keeps the previous target's value. Rebased onto main after #1205: the edit-load block withdraws the dialog's transients and then resets the fields. Closes #1156
Problem
ConnectionModalis published (src/exports/components.ts, andpackage.jsonexports./components), so a host can replaceeditConnectionwhileisOpenstays true. The standalone app cannot reach this:Studio.tsxclearseditingConnectiontogether withisOpenin bothonCloseandonConnect, and the dialog is modal.The degraded-save offer in
handleConnectsaves only on the second click and remembers the first one indegradedSaveAcknowledged. The comment above that branch said the acknowledgement "is withdrawn when the dialog closes", and the close reset block was indeed the only place that withdrew it. The block that applies a new edit target (guarded byappliedEdit.conn !== editConnection) cleared none of the four transient values, so a target that arrived without a close inherited all of them.The consequence is a silent first save: Y's health read is refused, Y is handed to
onConnecton the first click with nothing reported, and X's "click again" banner is shown over it.Change
The close path's four
set*calls and the new call in the edit-load block are now one function,withdrawTransientState, called from both. That is the shape the issue asks for and the reason for it: two copies of that list had already drifted once, which is this bug, and would be free to drift again.The trigger is the block's existing one, unchanged. A rerender carrying the same target is not a new connection and must not withdraw anything, or the second click becomes unreachable for any host that re-renders while the dialog is open.
The comment above the degraded branch now names both triggers this hook owns and points at #1167 for the third (withdrawal after a successful save), which is that issue's work, not this one's.
No comparison by
idor any other new condition was added, and the four fields, the build, and the save path are untouched.Tests
Two tests in
tests/hooks/use-connection-form.test.ts, beside the existing "closing the dialog withdraws the acknowledgement" and in the same shape:handleConnect()warns, rerender with Y while still open. AssertstestResultisnull, the name is Y, Y's firsthandleConnect()does not callonConnectand leaves a warning, and the second saves Y.handleConnect()saves X with no second warning. This one passes before the fix as well, and it is here because a fix that withdrew on every render would pass the first test alone.The first test fails on
mainand passes with the fix. Proven by sabotage rather than asserted: removing the single new call from the edit-load block and leaving the helper in place turns that test red while the same-target test stays green, and restoring the file returns both to passing.tests/hooks/use-connection-form.test.tsis 115/115, including the existing degraded-save tests unchanged.use-connection-form.tsis at 100% line coverage.Verification
bun run format,lint,typecheck,knip,chart:check,channels:showcase:check,readme:check,security:checkall passinspect-schema,run-read-query) are the pre-existing MCP pair that also fails onmainand on the openGauss branchNote on the base
#1157 and #1167 both change this file and the blocks next to this one, and the issue asks for a branch from
mainafter both land. Both are still open, so this is branched from currentmainand will need a rebase if either lands first. The fix is deliberately confined to the two blocks the issue names, to keep that rebase small.Fixes #1180