Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: guard stale Character Sheet name blur-save while prior PUT in flight (#2409)

Adam Eivybc63146ec3b1
diff --git a/client/src/pages/CharacterSheet.a11y.test.jsx b/client/src/pages/CharacterSheet.a11y.test.jsx
index 6494480f07..4cede47a24 100644
--- a/client/src/pages/CharacterSheet.a11y.test.jsx
+++ b/client/src/pages/CharacterSheet.a11y.test.jsx
@@ -85,6 +85,34 @@ describe('CharacterSheet name editing accessibility', () => {
);
});
+ it('blocks reopening the editor while a prior name-save PUT is in flight (#2409)', async () => {
+ // Hold the first save open so we can attempt a stale reopen mid-flight.
+ let resolvePut;
+ put.mockImplementationOnce((_path, body) =>
+ new Promise((resolve) => { resolvePut = () => resolve({ ...CHAR, ...body }); }),
+ );
+
+ renderSheet();
+ fireEvent.click(await findNameTrigger());
+ const input = screen.getByLabelText('Character name');
+ fireEvent.change(input, { target: { value: 'Strider' } });
+ fireEvent.keyDown(input, { key: 'Enter' });
+
+ // First PUT is now pending; the trigger is back but disabled, so a click
+ // (which would seed a stale 'Aragorn' input) is a no-op.
+ const trigger = await screen.findByRole('button', { name: /edit character name/i });
+ expect(trigger).toBeDisabled();
+ fireEvent.click(trigger);
+ expect(screen.queryByLabelText('Character name')).toBeNull();
+
+ // Resolve the save: exactly one PUT fired (no stale revert), editor reopenable.
+ resolvePut();
+ await waitFor(() => expect(put).toHaveBeenCalledTimes(1));
+ await waitFor(() =>
+ expect(screen.getByRole('button', { name: /edit character name/i })).not.toBeDisabled(),
+ );
+ });
+
it('cancels the edit on Escape and restores the original name', async () => {
renderSheet();
fireEvent.click(await findNameTrigger());
diff --git a/client/src/pages/CharacterSheet.jsx b/client/src/pages/CharacterSheet.jsx
index bf7e637e34..543ae7bd14 100644
--- a/client/src/pages/CharacterSheet.jsx
+++ b/client/src/pages/CharacterSheet.jsx
@@ -59,6 +59,10 @@ export default function CharacterSheet() {
const [editingClass, setEditingClass] = useState(false);
const [nameVal, setNameVal] = useState('');
const [classVal, setClassVal] = useState('');
+ // True while a name-save PUT is in flight. Gates re-opening the editor so a
+ // reopened input (still showing the pre-save name) can't blur-save a stale
+ // value back over the name the in-flight PUT is about to persist (#2409).
+ const [nameSaving, setNameSaving] = useState(false);
const [syncing, setSyncing] = useState(null);
const [generatingAvatar, setGeneratingAvatar] = useState(false);
const [diffusionProgress, setDiffusionProgress] = useState(null);
@@ -194,6 +198,10 @@ export default function CharacterSheet() {
};
const startNameEdit = () => {
+ // Refuse to reopen while a prior save is still in flight — the reopened
+ // input would seed from the pre-save `char.name` and a subsequent blur
+ // could persist that stale value over the pending save (#2409).
+ if (nameSaving) return;
nameEditingRef.current = true;
setNameVal(char.name || '');
setEditingName(true);
@@ -209,12 +217,16 @@ export default function CharacterSheet() {
setNameVal(char.name || '');
return;
}
+ if (!(nameVal.trim() && nameVal.trim() !== char.name)) return;
+ setNameSaving(true);
try {
- if (nameVal.trim() && nameVal.trim() !== char.name) {
- const data = await charPut({ name: nameVal.trim() });
- setChar(data);
- }
- } catch (err) { toast.error(err.message || 'Failed to save name'); }
+ const data = await charPut({ name: nameVal.trim() });
+ setChar(data);
+ } catch (err) {
+ toast.error(err.message || 'Failed to save name');
+ } finally {
+ setNameSaving(false);
+ }
};
// Enter commits, Escape cancels. preventDefault keeps Enter from triggering
@@ -370,8 +382,9 @@ export default function CharacterSheet() {
<button
type="button"
onClick={startNameEdit}
+ disabled={nameSaving}
aria-label={`Edit character name (currently ${char.name || 'Unnamed Hero'})`}
- className="text-2xl font-bold text-white cursor-pointer hover:text-port-accent transition-colors truncate text-left bg-transparent border-0 p-0"
+ className="text-2xl font-bold text-white cursor-pointer hover:text-port-accent transition-colors truncate text-left bg-transparent border-0 p-0 disabled:opacity-60 disabled:cursor-wait"
>
{char.name || 'Unnamed Hero'}
</button>