Skip to content

fix: keep a saved prompt variable open and guard unsaved edits (#6023) - #6136

Merged
atomantic merged 1 commit into
mainfrom
claim/issue-6023
Sep 3, 2026
Merged

fix: keep a saved prompt variable open and guard unsaved edits (#6023)#6136
atomantic merged 1 commit into
mainfrom
claim/issue-6023

Conversation

@atomantic

@atomantic atomantic commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

The Prompt Manager's Variables tab treated a successful save like a reset. saveVariable cleared ?var= from the URL and blanked every field with { silent: true } suppressing the only feedback, so editing Tone Guide and clicking Save dropped the user into an empty "New Variable" form with no toast — indistinguishable from a crash. Verifying what had just been written meant finding the variable in the list and clicking it again. Creating a variable landed the same blank form instead of opening what was created, and deleting one finished in silence.

Separately, the list was destructive: variable content runs to paragraphs of prompt instructions, and clicking another row (or the "+") overwrote varForm immediately, with no way back.

What changed (client/src/pages/PromptManager.jsx)

Save / create / delete feedback

  • Saving an existing variable keeps it selected and keeps the saved text in the form, and toasts Variable "<name>" saved. The post-save loadData() cannot re-hydrate over it — varHydratedRef still holds the open key.
  • Creating toasts Variable "<key>" created and adopts the new key as ?var=<key>after the refreshed list holds it, so the "variable could not be found" panel can't flash on the way in.
  • Deleting toasts Variable "<name>" deleted.
  • A save that lands after the user has moved on re-baselines nothing, so it can't stamp the outgoing variable's text as the incoming one's saved state.

Unsaved-edit guard

  • savedVarForm tracks the last server-confirmed form as a full copy (not a boolean), so typing an edit and undoing it stops counting as dirty.
  • The open list row and the editor header show an Unsaved badge / Unsaved changes note while dirty.
  • Clicking another variable, or the "+", parks the request in pendingVar and turns that slot into a Discard / Keep editing InlineConfirmRow instead of switching. The "+" has no row of its own, so its question takes the top of the list.
  • Create-mode drafts count as dirty too — a typed-but-unsaved new variable is exactly the work "+" would otherwise throw away.
  • Arming a delete disarms a pending switch and vice versa, so a row is never asking two questions at once.

This is the same inline-confirmation shape the Stages (#6021) and Job Skills (#3939) tabs already use. No window.confirm; selection stays in the URL.

Test plan

client/src/pages/PromptManager.test.jsx — new PromptManager variable editing suite (8 tests). All 8 verified failing against the pre-fix component (swapped in origin/main's PromptManager.jsx, ran the suite, restored):

  • saved variable stays open, keeps its edited content, and toasts — asserted against a refetch that still returns the pre-save fixture, which is the re-hydration regression
  • created variable toasts and lands in ?var=<key> with its content intact
  • delete toasts
  • editing then clicking another variable arms the discard row rather than switching
  • "Keep editing" preserves the edits and the selection
  • "Discard" switches to the clicked variable
  • "+" asks first, then opens the blank form
  • undoing an edit back to the saved value disarms the question — no prompt on the next click
cd client && npx vitest run src/pages/PromptManager.test.jsx
  Tests  71 passed (71)

Full client suite: 832 passed | 1 skipped. The one intermittent failure seen on one run was src/components/ui/PageSkeleton.test.jsx (getAllByRole('status')[0] / aria-busy), which passes in isolation across repeated runs and is untouched by this diff.

npx biome check clean on both changed files.

Closes #6023

https://claude.ai/code/session_01RA3pD5YM2dukQwbZ3pC6WA

Saving a prompt variable in the Variables tab deselected it, dropped `?var=`
from the URL, and blanked every field — with no toast — so a successful save
looked exactly like a crash, and checking what had just been written meant
hunting the variable down in the list and clicking it again. Creating one
landed the same blank form instead of opening what was created, and a delete
finished in silence.

Saving now leaves the variable open on what was saved and confirms it with a
toast; creating adopts the new key as the URL selection once the refreshed list
holds it (so the "variable could not be found" panel can't flash on the way);
deleting says which variable went.

Switching variables also stopped being destructive. Variable content runs to
paragraphs of instructions, and clicking another row — or the "+" — used to
overwrite the editor with no warning. The tab now tracks the loaded form as a
saved baseline, badges the open row and editor "Unsaved", and turns the
requested slot into a "Discard / Keep editing" row instead of switching. The
"+" question takes the top of the list since it has no row of its own. Undoing
the edit back to the saved values clears the prompt on its own.

Same inline-confirmation shape the Stages (#6021) and Job Skills (#3939) tabs
already use — no window.confirm.

Claude-Session: https://claude.ai/code/session_01RA3pD5YM2dukQwbZ3pC6WA
@atomantic
atomantic merged commit 5b26a33 into main Sep 3, 2026
7 checks passed
@atomantic
atomantic deleted the claim/issue-6023 branch September 3, 2026 22:58
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.

PromptManager: Variables tab Save abruptly deselects and blanks editor without confirmation; switching variables discards edits

1 participant