From eed27185ee210a26b42e2e2ee54b1bdc4eda53b9 Mon Sep 17 00:00:00 2001 From: Chema Date: Thu, 8 Oct 2026 22:04:53 +0200 Subject: [PATCH] Fix a race when renaming a session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dismissing the rename alert cleared AppModel.renaming to nil right away, but the Rename button's Task only read renaming after an await, by which point it was already gone — so renaming silently did nothing. Capture the prompt synchronously when the button is tapped instead. --- App/AppModel.swift | 6 +++--- App/MainView.swift | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/App/AppModel.swift b/App/AppModel.swift index 783dea1..bfa6ab9 100644 --- a/App/AppModel.swift +++ b/App/AppModel.swift @@ -619,9 +619,9 @@ final class AppModel { renaming = RenamePrompt(session: id, workspaceID: workspaceID, name: context.target.workspace) } - func commitRename() async { - guard let prompt = renaming else { return } - renaming = nil + /// Takes the prompt as it was when the button was tapped: dismissing the alert clears + /// `renaming` right away, before an awaited `Task` would get a chance to read it. + func commitRename(_ prompt: RenamePrompt) async { let name = prompt.name.trimmingCharacters(in: .whitespacesAndNewlines) guard !name.isEmpty, name != context(for: prompt.session)?.target.workspace else { return } do { try await cluster.renameWorkspace(prompt.workspaceID, to: name, onMachine: prompt.session.machineID) } diff --git a/App/MainView.swift b/App/MainView.swift index 1121020..8861bf1 100644 --- a/App/MainView.swift +++ b/App/MainView.swift @@ -64,7 +64,10 @@ struct MainView: View { view .alert("Rename Session", isPresented: Binding { model.renaming != nil } set: { if !$0 { model.renaming = nil } }) { TextField("Name", text: Binding { model.renaming?.name ?? "" } set: { model.renaming?.name = $0 }) - Button("Rename") { Task { await model.commitRename() } } + Button("Rename") { + guard let prompt = model.renaming else { return } + Task { await model.commitRename(prompt) } + } Button("Cancel", role: .cancel) { model.renaming = nil } } message: { Text("Renames its Herdr workspace. Other panes in the same workspace share the name.")