Skip to content

Library and pane mutations ignore res.ok and show changes that were never saved #423

Description

@charlesrhoward

Problem

Save, create and delete in the Library rules section call fetch, then immediately update local state and revalidate. A 403 or 500 leaves the UI showing the edit as applied. The same shape appears in ten other components.

Where

  • components/library/rules-section.tsx:28-55 (saveFile, createFile, deleteFile).
  • components/library/context-section.tsx (five fetches, no error handling).
  • components/panes/output-pane.tsx, components/panes/connections-pane.tsx, components/panes/agent-roster-pane.tsx, components/panes/diff-pane.tsx.
  • app/(dashboard)/[scope]/assignments/page.tsx, components/agent-editor.tsx, components/app-sidebar.tsx, components/top-bar.tsx, components/active-scope-provider.tsx.

Helpers that already exist: lib/client-fetch.ts has readJson and error-message extraction. The app already has a toast component (check components/ui/ for sonner or toast).

Fix

  1. Add mutateJson(url, init) to lib/client-fetch.ts: performs the fetch, throws an Error with the server's message when !res.ok, returns parsed JSON otherwise.
  2. Replace every bare mutation fetch in the files above with mutateJson inside try/catch. On error, show a toast with the message and do not update local state.
  3. Work file by file. One PR per two or three files is fine; link them all here.

Exit criteria

  • mutateJson has a vitest test in lib/client-fetch.test.ts covering the OK path and the error path with a server message.
  • rg -n 'await fetch\(' components/library components/panes app/\(dashboard\)/\[scope\]/assignments returns no mutation calls (GET fetches inside SWR fetchers are fine).
  • Manual: block PUT /api/rules in DevTools, edit a rule, confirm a toast appears and the editor keeps the unsaved content.
  • pnpm lint, pnpm typecheck, pnpm test pass.

Out of scope

Adding AbortController to the GET fetches in the same files. Separate issue.

https://claude.ai/code/session_01SQ4nS96XYRztd5w9QkubPf

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Reliability or a user-visible class of bug.bugSomething isn't workingux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions