Skip to content

fix: note delete in ContextSidebar updates UI optimistically without checking response status #262

Description

@nazarli-shabnam

Problem

The note-delete handler removes the note from local state unconditionally after the fetch settles, without checking `res.ok`, and even a caught network error still falls through to the state update:

```ts
const remove = async (id: number) => {
if (!accessToken) return;
await fetch(`/api/notes/${id}`, { method: "DELETE", ... }).catch((e) => console.error(...));
setNotes((prev) => prev.filter((n) => n.id !== id));
};
```

Impact

If the DELETE request fails server-side (4xx/5xx) or errors over the network, the UI still shows the note as deleted immediately, while it actually still exists in the database. The note will reappear the next time notes are reloaded, which is confusing — the user believed it was permanently removed and may have relied on that (e.g. re-typed sensitive content elsewhere assuming the original was gone).

Location

`components/layout/ContextSidebar.tsx:125-132`

Suggested fix

Only strip the note from local state when the response is `ok`; on failure, keep the note in state and surface an error (toast/inline message), mirroring the pattern already used for the `save` handler in the same file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions