Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(skills): keep text typed while a save is in flight (#11488)
pseudoyu58ca589df43c
diff --git a/packages/views/skills/components/skill-detail-page.test.tsx b/packages/views/skills/components/skill-detail-page.test.tsxindex f8a729ba54..0efe8d671a 100644--- a/packages/views/skills/components/skill-detail-page.test.tsx+++ b/packages/views/skills/components/skill-detail-page.test.tsx@@ -755,3 +755,80 @@ describe("SkillDetailPage draft baseline (MUL-5645)", () => {expect(field.value).toBe("my unsaved edit");});});++describe("SkillDetailPage edits made while a save is in flight", () => {+ /** Starts a save whose response the test releases by hand. */+ async function startSave() {+ let release!: (saved: Partial<Skill>) => void;+ vi.mocked(api.updateSkill).mockImplementationOnce(+ (_id, payload) =>+ new Promise((resolve) => {+ release = (saved) => {+ const next = {+ ...baseSkill,+ ...payload,+ // The server recreates every file row on save, so ids change.+ files: (payload.files ?? []).map((f, i) => ({ ...f, id: `saved-${i}` })),+ updated_at: "2026-07-29T10:00:00Z",+ ...saved,+ } as Skill;+ skillRef.current = next;+ resolve(next);+ };+ }),+ );+ await userEvent.click(screen.getByRole("button", { name: /Save changes/ }));+ return async (saved: Partial<Skill> = {}) => {+ release(saved);+ await vi.waitFor(() => expect(toast.success).toHaveBeenCalled());+ };+ }++ it("keeps text typed into SKILL.md and leaves it unsaved", async () => {+ renderPage(new URLSearchParams("view=files"));+ fireEvent.click(await screen.findByRole("button", { name: "Edit" }));+ const editor = screen.getByRole("textbox", { name: /SKILL\.md/ });+ fireEvent.change(editor, { target: { value: "first" } });+ const finish = await startSave();+ fireEvent.change(editor, { target: { value: "first and second" } });+ await finish();++ expect(screen.getByRole("textbox", { name: /SKILL\.md/ })).toHaveValue("first and second");+ expect(screen.getByText("Changed: 1 file")).toBeTruthy();+ expect(screen.queryByText("Someone else updated this skill")).toBeNull();+ });++ it("keeps text typed into a supporting file without marking the others changed", async () => {+ skillRef.current = {+ ...baseSkill,+ files: [+ ...baseSkill.files,+ { id: "f-2", path: "other.md", content: "# Other\n" } as Skill["files"][number],+ ],+ };+ renderPage(new URLSearchParams("view=files"));+ fireEvent.click(await screen.findByRole("button", { name: "Edit" }));+ fireEvent.click(screen.getByRole("tab", { name: "patterns.md" }));+ const editor = screen.getByRole("textbox", { name: /patterns\.md/ });+ fireEvent.change(editor, { target: { value: "first" } });+ const finish = await startSave();+ fireEvent.change(editor, { target: { value: "first and second" } });+ await finish();++ expect(screen.getByRole("textbox", { name: /patterns\.md/ })).toHaveValue("first and second");+ expect(screen.getByText("Changed: 1 file")).toBeTruthy();+ });++ it("takes the saved version of the fields nobody touched meanwhile", async () => {+ renderPage();+ const name = await screen.findByLabelText("Name");+ fireEvent.change(name, { target: { value: "renamed" } });+ const finish = await startSave();+ fireEvent.change(await openDescription(), { target: { value: "typed later" } });+ await finish({ name: "renamed-by-server" });++ expect(screen.getByLabelText("Name")).toHaveValue("renamed-by-server");+ expect(screen.getByLabelText("Description")).toHaveValue("typed later");+ expect(screen.getByText(/^Changed:/).textContent).toBe("Changed: Description");+ });+});diff --git a/packages/views/skills/components/skill-detail-page.tsx b/packages/views/skills/components/skill-detail-page.tsxindex a558c6309d..d2e7c95961 100644--- a/packages/views/skills/components/skill-detail-page.tsx+++ b/packages/views/skills/components/skill-detail-page.tsx@@ -173,6 +173,37 @@ function hasLocalEdits(draft: SkillDraft, baseline: SkillDraft | null): boolean);}+/**+ * The draft to show once a save returns: the saved version, except the fields+ * the user changed after `sent` left the page. Saving recreates every file row,+ * so kept files take their new id from the path they were sent under.+ */+function draftAfterSave(+ draft: SkillDraft,+ sent: SkillDraft,+ saved: SkillDraft,+): SkillDraft {+ const sentPathById = new Map(sent.files.map((f) => [f.id, f.path]));+ const savedIdByPath = new Map(saved.files.map((f) => [f.path, f.id]));+ return {+ name: draft.name === sent.name ? saved.name : draft.name,+ description:+ draft.description === sent.description+ ? saved.description+ : draft.description,+ content: draft.content === sent.content ? saved.content : draft.content,+ files:+ draft.files === sent.files+ ? saved.files+ : draft.files.map((f) => ({+ ...f,+ id: savedIdByPath.get(+ (f.id ? sentPathById.get(f.id) : undefined) ?? f.path,+ ),+ })),+ };+}+/*** The page body: the skill's sections, its files beside an editor, or its* version history. Files and versions need more width than the reading@@ -445,34 +476,38 @@ export function SkillDetailPage({ skillId }: { skillId: string }) {* The draft this page last handed the user, normalized by `toDraft`. Dirty* state is measured against THIS, never against the latest server skill.*- * INVARIANT: `seedFromSkill` is the only writer, and it always writes the- * same snapshot it pushes into state. `dirtySummary` is a `useMemo` keyed on- * those state values, so every baseline write is paired with the state- * change that recomputes it. Assigning this ref anywhere else breaks that+ * INVARIANT: `seedFromSkill` is the only writer, and it always pushes a new+ * `files` array into state with it. `dirtySummary` is a `useMemo` keyed on+ * that state, so every baseline write is paired with the state change that+ * recomputes it. Assigning this ref anywhere else breaks that* pairing and silently re-opens MUL-5645.*/const baselineRef = useRef<SkillDraft | null>(null);- const seedFromSkill = useCallback((s: Skill) => {- const seeded = toDraft(s);+ const seedFromSkill = useCallback((s: Skill, sent?: SkillDraft) => {+ const baseline = toDraft(s);+ const seeded = sent+ ? draftAfterSave(draftRef.current, sent, baseline)+ : baseline;setName(seeded.name);setDescription(seeded.description);setContent(seeded.content);setFiles(seeded.files);- baselineRef.current = seeded;+ baselineRef.current = baseline;}, []);/*** Adopt a server version wholesale: draft, baseline, seeded key and conflict* flag all move together. Every path that accepts a server version goes* through here — first load, silent refresh, Save, Discard — so the four- * pieces can never drift apart.+ * pieces can never drift apart. Save passes the draft it `sent`, so edits+ * made while the request was in flight stay in the draft.*/const adoptServerVersion = useCallback(- (s: Skill, resetSelection = false) => {+ (s: Skill, resetSelection = false, sent?: SkillDraft) => {seededKeyRef.current = `${wsId}:${s.id}@${s.updated_at}`;setConflictPending(false);- seedFromSkill(s);+ seedFromSkill(s, sent);if (resetSelection) setSelectedPath(SKILL_MD);},[wsId, seedFromSkill],@@ -612,6 +647,7 @@ export function SkillDetailPage({ skillId }: { skillId: string }) {if (!skill || !canEdit) return;const trimmedName = name.trim();const trimmedDesc = description.trim();+ const sent = { name, description, content, files };setSaving(true);try {const payload: UpdateSkillRequest = {@@ -622,7 +658,7 @@ export function SkillDetailPage({ skillId }: { skillId: string }) {};const updated = await api.updateSkill(skill.id, payload);qc.setQueryData(skillDetailOptions(wsId, skill.id).queryKey, updated);- adoptServerVersion(updated);+ adoptServerVersion(updated, false, sent);qc.invalidateQueries({queryKey: workspaceKeys.skills(wsId),exact: true,