Agent skill

Frontend Optimistic Mutations

by sickn33 in sickn33/agentic-awesome-skills

A portable, framework-agnostic discipline for the write path of any React or React Native app using a query/cache layer.

MITAuto-check passedMobile

Install Frontend Optimistic Mutations

skills CLI
$ npx skills add sickn33/agentic-awesome-skills --skill frontend-optimistic-mutations -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install sickn33/agentic-awesome-skills frontend-optimistic-mutations --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/sickn33/agentic-awesome-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/frontend-optimistic-mutations .claude/skills/frontend-optimistic-mutations && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
frontend-optimistic-mutations
GitHub stars
47k
Used in
1 other repo
Token cost
~3.6k tokens
SKILL.md length
1,241 words
Files
1
Skills in repo
1,493
Repo updated
First seen
Licence
MIT

At a glance

A portable, framework-agnostic discipline for the write path of any React or React Native app using a query/cache layer.

  • Works in 10 steps: The five core ideas → When to be optimistic (and when not) → The optimistic lifecycle (TanStack Query) → …
  • Tasks that involve Cross-platform mobile apps
  • SKILL.md covers When to Use, 0. The five core ideas, 1. When to be optimistic (and… and 2. The optimistic lifecycle…, plus 9 more sections
  • Calls npx

What it does

Frontend Optimistic Mutations is an agent skill from sickn33/agentic-awesome-skills. A portable, framework-agnostic discipline for the write path of any React or React Native app using a query/cache layer.

Its SKILL.md is about 3.6k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile, covering Cross-platform mobile apps. It works with React and React Native. The repository describes itself as: AAS Core is the local, agent-first control plane for complete catalog discovery, agent-owned selection, stack validation, and planning, backed by 2,400+ agentic skills. Includes… The licence is MIT.

When your agent uses it

  • Tasks that involve Cross-platform mobile apps

Example prompts

  • “/frontend-optimistic-mutations”

Workflow steps

10 steps, taken from the step headings in SKILL.md.

  1. The five core ideas
  2. When to be optimistic (and when not)
  3. The optimistic lifecycle (TanStack Query)
  4. Non-optimistic writes: create with server-owned fields
  5. Cache coherence (lock-step detail + lists)
  6. Idempotency (safe retries on money-moving writes)
  7. Retry policy
  8. Library adapters
  9. Conventions checklist (enforce in review)
  10. How to apply this skill

What it can do on your machine

Read from SKILL.md and the folder at commit 680176d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npx

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npx, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Frontend Optimistic Mutations loads about 3.6k tokens when it runs. Until then it costs about 38 tokens; SKILL.md has 1,241 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~38
When it runs · the whole SKILL.md, loaded when a task matches
~3.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from sickn33/agentic-awesome-skills at commit 680176d, republished under its MIT licence (© sickn33). 1,241 words, ~3,555 tokens.

Download SKILL.mdSave it as .claude/skills/frontend-optimistic-mutations/SKILL.md (or your agent's skills folder).
name
frontend-optimistic-mutations
description
A portable, framework-agnostic discipline for the write path of any React or React Native app using a query/cache layer.
risk
critical
source
https://github.com/stareezy-1/frontend-architecture-skill/tree/main/skills/frontend-optimistic-mutations
source_repo
stareezy-1/frontend-architecture-skill
source_type
community
date_added
2026-07-01
license
MIT
license_source
https://github.com/stareezy-1/frontend-architecture-skill/blob/main/LICENSE

Frontend Optimistic Mutations (the write path)

When to Use

Use this skill when you need a portable, framework-agnostic discipline for the write path of any React or React Native app using a query/cache layer. Codifies the optimistic-update lifecycle (cancel in-flight queries → snapshot every affected cache → patch instantly → roll back verbatim on error → invalidate on...

Portable skill — readable by Claude Code, OpenCode, Codex, Cursor, Windsurf, and others. This skill describes the discipline of the write path — optimistic updates, rollback, idempotency, cache coherence — not a UI library or a styling system. It builds directly on the frontend-data-contracts skill (writes go through the typed client) and the frontend-architecture skill (mutations live in modules/{feature}/hooks/, keyed by a factory).

The goal: a write feels instant (the UI reflects it before the server confirms), is safe (a failure restores the exact prior state, and a retry never double-charges), and leaves the cache coherent (the detail view and every list page agree). All three at once — that's the craft.


0. The five core ideas

  1. The optimistic lifecycle is fixed. cancel → snapshot → patch → (error: roll back) → (settle: invalidate). Every optimistic mutation follows the same five beats.
  2. Roll back verbatim. On failure, restore the exact snapshot taken before the patch — not a "best guess" re-derivation. Keep the snapshot in mutation context.
  3. Idempotency is generated once, not per attempt. The key is created at form init (or first intent), so a network retry replays the original server response instead of performing the action twice.
  4. Caches move in lock-step. A status change patches the detail cache and every list page that contains the entity, so badges never disagree across surfaces.
  5. Server state never enters the client store. Optimistic state lives in the query cache, not Zustand/Redux. The cache is the single source of truth for server data (per frontend-architecture §4).

1. When to be optimistic (and when not)

SituationStrategy
High-confidence, low-conflict write (toggle status, like, mark-paid, reorder)Optimistic — patch immediately, roll back on error.
Create that returns a server-generated id/number/totalPending state, then setQueryData from the server response. A temporary optimistic row is optional; reconcile on success.
Destructive or hard-to-reverse write (delete with cascade, send money)Confirm first, then optimistic or pending — never silent-optimistic.
Write whose result the user can't see yet (background job)Pending + toast, invalidate when done. No optimistic patch.

Optimism is a UX tool for writes you're confident will succeed. If failure is common or expensive to undo, prefer a pending state.


2. The optimistic lifecycle (TanStack Query)

The canonical shape. Each beat has a job; skipping one breaks correctness.

ts
// modules/invoice/hooks/useInvoiceMutations.ts
interface MarkPaidContext {
  previousInvoice: Invoice | undefined; // detail snapshot
  previousLists: Array<[readonly unknown[], InvoiceListResponse]>; // every list page snapshot
}

export function useMarkInvoicePaid() {
  const queryClient = useQueryClient();
  const notifyError = useApiErrorToast();

  return useMutation<Invoice, ApiError, { id: InvoiceId }, MarkPaidContext>({
    mutationFn: ({ id }) => apiClient.post<Invoice>(INVOICE_API.markPaid(id)),

    // 1 + 2 + 3: cancel in-flight reads, snapshot, patch
    onMutate: async ({ id }) => {
      await queryClient.cancelQueries({ queryKey: invoiceKeys.all }); // (1) no late refetch clobber

      const detailKey = invoiceKeys.detail(id);
      const previousInvoice = queryClient.getQueryData<Invoice>(detailKey); // (2) snapshot detail
      if (previousInvoice) {
        queryClient.setQueryData<Invoice>(detailKey, {
          // (3) patch detail
          ...previousInvoice,
          status: InvoiceStatus.Paid,
        });
      }

      const previousLists: MarkPaidContext["previousLists"] = [];
      for (const [key, list] of queryClient.getQueriesData<InvoiceListResponse>(
        {
          queryKey: invoiceKeys.lists(),
        },
      )) {
        if (!list) continue;
        previousLists.push([key, list]); // (2) snapshot each page
        if (!list.invoices.some((i) => i.id === id)) continue;
        queryClient.setQueryData<InvoiceListResponse>(key, {
          // (3) patch matching row
          ...list,
          invoices: list.invoices.map((i) =>
            i.id === id ? { ...i, status: InvoiceStatus.Paid } : i,
          ),
        });
      }
      return { previousInvoice, previousLists };
    },

    // 4: roll back verbatim
    onError: (error, { id }, ctx) => {
      if (ctx?.previousInvoice)
        queryClient.setQueryData(invoiceKeys.detail(id), ctx.previousInvoice);
      for (const [key, list] of ctx?.previousLists ?? [])
        queryClient.setQueryData(key, list);
      notifyError(error);
    },

    // 5: invalidate so authoritative server state (paidAt, aggregates) refetches
    onSettled: (_d, _e, { id }) => {
      void queryClient.invalidateQueries({ queryKey: invoiceKeys.detail(id) });
      void queryClient.invalidateQueries({ queryKey: invoiceKeys.lists() });
    },
  });
}

Why each beat:

  • cancel — without it, a query that was already in flight can resolve after your patch and overwrite the optimistic state.
  • snapshot — the only safe rollback source; never reconstruct prior state by hand.
  • patch — the instant UX; mutate detail and lists together (§4).
  • roll back — restore snapshots verbatim, then surface the typed ApiError.
  • invalidate on settle — success or failure, refetch so server-computed fields (timestamps, totals) are authoritative. Settle, not just success: a failed write may still have changed server state.

3. Non-optimistic writes: create with server-owned fields

A create that returns an id/number/total can't be fully optimistic. Run it as a pending mutation and seed the cache from the response.

ts
export function useCreateInvoice() {
  const queryClient = useQueryClient();
  return useMutation<Invoice, ApiError, CreateInvoiceInput>({
    mutationFn: ({ document, idempotencyKey }) =>
      apiClient.post<Invoice>("/invoices", document, { idempotencyKey }),
    onSuccess: (invoice) => {
      queryClient.setQueryData(invoiceKeys.detail(invoice.id), invoice); // seed detail
      void queryClient.invalidateQueries({ queryKey: invoiceKeys.lists() }); // refresh lists
    },
    onError: (error) => notifyError(error),
  });
}

4. Cache coherence (lock-step detail + lists)

A single entity appears in many caches: its detail, and every filtered/paginated list page. An optimistic patch must touch all of them or surfaces disagree. Use a hierarchical key factory (from frontend-architecture §4.3) so you can target precisely.

ts
export const invoiceKeys = {
  all: ["invoices"] as const,
  lists: () => [...invoiceKeys.all, "list"] as const,
  list: (p: IListParams) => [...invoiceKeys.lists(), p] as const,
  detail: (id: InvoiceId) => [...invoiceKeys.all, "detail", id] as const,
} as const;
  • getQueriesData({ queryKey: invoiceKeys.lists() }) enumerates every cached list page so you can patch each.
  • invalidateQueries({ queryKey: invoiceKeys.lists() }) refreshes them all on settle.
  • detail(id) targets exactly one entity.

Snapshot each page you touch (keyed by its exact query key) so rollback restores every page verbatim, not just the one currently on screen.


5. Idempotency (safe retries on money-moving writes)

A retried POST must not perform the action twice. Generate the key once, at form init (or first user intent), carry it through retries, and let the client send it as a header. The server replays the original response for a repeated key within its window.

ts
// at form initialisation — stable for the lifetime of this attempt
const idempotencyKey = useMemo(() => crypto.randomUUID(), []);

// mutation forwards it; the typed client puts it on the header
apiClient.post<Invoice>("/invoices", document, { idempotencyKey });

Hard rules:

  • Generate the key at intent time, not inside mutationFn (which re-runs per retry → defeats the purpose).
  • The data client auto-detects financial routes and injects the header; an explicit key always wins so retries replay.
  • Pair idempotency with disabled-while-pending UI so the user can't fire a second distinct write.

Show full SKILL.md (504 more words)Show less

6. Retry policy

  • Reads: retry a few times with backoff (default in most query libs) — safe and idempotent.
  • Writes: do not auto-retry non-idempotent mutations. Retry only when an idempotency key guarantees replay, or only on network errors (status 0), never on 4xx.
  • Conflicts (409): don't retry — surface the typed error, invalidate, and let the user re-decide on fresh data.
ts
useMutation({
  retry: (count, error: ApiError) => error.isNetworkError && count < 2, // network-only, bounded
});

7. Library adapters

The five-beat lifecycle is the same; the hooks differ.

LibraryOptimistic mechanism
TanStack QueryonMutate (cancel + snapshot + patch) → onError (rollback) → onSettled (invalidate). The reference shape above.
RTK QueryonQueryStarted: updateQueryData returns a patchResult; await queryFulfilled and call patchResult.undo() in catch. invalidatesTags on settle.
SWRmutate(key, optimisticData, { rollbackOnError: true, populateCache, revalidate: true }) — optimistic data + automatic rollback + revalidate.

For React Native, all three libraries work unchanged; the cache is the source of truth on native too. Keep mutation hooks DOM-free so they're shareable across web and native.


8. Conventions checklist (enforce in review)

  • Optimistic mutations follow cancel → snapshot → patch → rollback → invalidate.
  • onMutate cancels in-flight queries before patching.
  • Rollback restores the exact snapshot from context, not a re-derivation.
  • Detail and every affected list page are patched and snapshotted together.
  • onSettled invalidates so server-computed fields are refetched (on success and error).
  • Idempotency key is generated at intent time and replayed across retries, not regenerated per attempt.
  • Money-moving / destructive writes confirm first and disable the trigger while pending.
  • Non-idempotent writes don't auto-retry; 409s surface rather than retry.
  • Server state stays in the query cache — never copied into a client store.
  • Query keys come from a hierarchical factory; invalidation is scoped, not global-blunt.

9. How to apply this skill

Adding an optimistic mutation: decide it's safe to be optimistic (§1). Write the five beats (§2). Identify every cache the entity lives in and patch/snapshot all of them (§4).

Making a write safe to retry: generate an idempotency key at form init, thread it through the mutation, confirm the client sends it (§5), and set a network-only bounded retry (§6).

Debugging a flicker / wrong-state-after-write: check that onMutate cancels queries (late refetch clobber) and that onSettled invalidates (stale server-computed fields). Check that all list pages were patched, not just the visible one.

Reviewing the write path: run the checklist in §8. The highest-value catches are missing cancelQueries (race clobber), partial cache patches (detail/list disagreement), and idempotency keys generated inside mutationFn (no longer protect retries).


Publishing / installing this skill

This skill follows the Anthropic SKILL.md format and is portable across agents.

  1. Keep it under skills/frontend-optimistic-mutations/SKILL.md in a public GitHub repo.
  2. Keep the frontmatter name and high-signal description — discovery indexes match against it.
  3. Install with: npx skills add <org>/<repo> --skill "frontend-optimistic-mutations".
  4. Non-SKILL.md agents can be pointed here from AGENTS.md / CLAUDE.md; Kiro can mirror it as a steering file.

Limitations

  • Use this skill only when the task clearly matches its upstream source and local project context.
  • Verify commands, generated code, dependencies, credentials, and external service behavior before applying changes.
  • Do not treat examples as a substitute for environment-specific tests, security review, or user approval for destructive or costly actions.

© sickn33, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/frontend-optimistic-mutations of sickn33/agentic-awesome-skills.

Open the folder on GitHubat commit 680176d

Used in 1 other repository

We found 5 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in sickn33/agentic-awesome-skills, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Frontend Optimistic Mutations next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Frontend Optimistic Mutations compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Frontend Optimistic Mutations this skillsickn33/agentic-awesome-skills47k1 repos~3.6kAutomated safety check: PassMIT
Add Featureecency/vision-mobile262—~1.9kAutomated safety check: PassMIT
ThemingCode-with-Beto/skills140—~2.5kAutomated safety check: PassNone
React Native Experttech-leads-club/agent-skills7k—~3.2kAutomated safety check: PassCC-BY-4.0
React Devtoolssanity-io/sanity6.4k3 repos~2.1kAutomated safety check: PassMIT
Screenmapaleqsio/screenmap243—~7.2kAutomated safety check: PassMIT

Similar skills

  • Add Feature

    ecency/vision-mobile

    A skill your agent uses when adding a new screen, route, or user-facing feature to the Ecency mobile React Native app, covering navigator registration, route params, i18n strings and styling.

    262 GitHub stars~1.9k tokensUpdated 3 days ago
    MobileAuto-check passed
  • Theming

    Code-with-Beto/skills

    Scaffold a unified, cross-platform color theme system into an Expo Router app.

    140 GitHub stars~2.5k tokensUpdated 2 mo ago
    MobileAuto-check passed
  • React Native Expert

    tech-leads-club/agent-skills

    Guides React Native and Expo work for cross-platform apps: Expo Router navigation, fast lists, Reanimated animation, platform-specific code and project structure.

    7k GitHub stars~3.2k tokensUpdated today
    MobileAuto-check passed
  • React Devtools

    sanity-io/sanity

    Official

    React DevTools CLI for AI agents. An agent skill from sanity-io/sanity.

    6.4k GitHub starsUsed in 3 repos~2.1k tokens
    MobileAuto-check passed
  • Screenmap

    aleqsio/screenmap

    Generate a visual navigation map of an Expo / React Native or NativeScript app.

    243 GitHub stars~7.2k tokensUpdated 4 days ago
    MobileAuto-check passed
  • Gestures

    kingstinct/react-native-healthkit

    Software Mansion's best practices for gestures in React Native apps using React Native Gesture Handler.

    716 GitHub starsUsed in 1 repo~1.7k tokens
    MobileAuto-check passed

More from sickn33/agentic-awesome-skills

All 1,493 skills in this repo
  • Liuguang Banlan UI

    sickn33/agentic-awesome-skills

    Implements an interface in one of two named color modes, iridescent white or colorful black, from a parameterized starter that reports measured color intensity.

    47k GitHub starsUsed in 1 repo~2.5k tokens
    Auto-check passed
  • User Thoughts Memory

    sickn33/agentic-awesome-skills

    Saves a user's project decisions, rules and preferences into a project-local mdbase so later sessions and other agents can recover the intent.

    47k GitHub starsUsed in 1 repo~2.5k tokens
    Auto-check passed
  • Using LWC Memory and Graphs

    sickn33/agentic-awesome-skills

    Keeps project decisions, research and verified results available across coding-agent sessions through LWC memory, a document Wiki graph and a CodeGraph code index.

    47k GitHub starsUsed in 1 repo~2k tokens
    Auto-check passed
  • Find Complementary Founders

    sickn33/agentic-awesome-skills

    Guides an agent through assessing its own owner for cofounder fit, publishing an approved profile, and ranking complementary profiles other agents published for their owners.

    47k GitHub starsUsed in 1 repo~4.8k tokens
    Auto-check passed
  • Whatsapp Cloud API

    sickn33/agentic-awesome-skills

    Integracao com WhatsApp Business Cloud API (Meta). An agent skill from sickn33/agentic-awesome-skills.

    47k GitHub starsUsed in 2 repos~4.5k tokens
    Auto-check passed
  • Cline Pilot

    sickn33/agentic-awesome-skills

    Acts as a proxy for the Cline CLI, dispatching coding tasks one at a time, monitoring runs by hard evidence, relaying decisions to you and learning per-project preferences.

    47k GitHub starsUsed in 1 repo~4.6k tokens
    Auto-check passed

Questions about Frontend Optimistic Mutations

What does Frontend Optimistic Mutations do?

A portable, framework-agnostic discipline for the write path of any React or React Native app using a query/cache layer. Frontend Optimistic Mutations is an agent skill from sickn33/agentic-awesome-skills. A portable, framework-agnostic discipline for the write path of any React or React Native app using a query/cache layer.

When should I use Frontend Optimistic Mutations?

Frontend Optimistic Mutations fits situations like: tasks that involve Cross-platform mobile apps.

How do I install Frontend Optimistic Mutations in Claude Code?

Run `npx skills add sickn33/agentic-awesome-skills --skill frontend-optimistic-mutations -a claude-code`. Or copy the skill folder (skills/frontend-optimistic-mutations in sickn33/agentic-awesome-skills) into .claude/skills/frontend-optimistic-mutations in your project. Claude Code loads it when a task matches its description.

How do I install Frontend Optimistic Mutations in Codex?

Run `npx skills add sickn33/agentic-awesome-skills --skill frontend-optimistic-mutations -a codex`. Or copy the skill folder (skills/frontend-optimistic-mutations in sickn33/agentic-awesome-skills) into .agents/skills/frontend-optimistic-mutations in your project. Codex loads it when a task matches its description.

Can I use Frontend Optimistic Mutations in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add sickn33/agentic-awesome-skills --skill frontend-optimistic-mutations -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/frontend-optimistic-mutations, .gemini/skills/frontend-optimistic-mutations, .github/skills/frontend-optimistic-mutations and .opencode/skills/frontend-optimistic-mutations in your project.

What does Frontend Optimistic Mutations need to run?

Going by SKILL.md and its folder, Frontend Optimistic Mutations needs the command-line tools its instructions call (npx).

Does Frontend Optimistic Mutations access the network?

SKILL.md contains no URLs. Its commands use npx, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Frontend Optimistic Mutations safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Frontend Optimistic Mutations use?

Frontend Optimistic Mutations is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Frontend Optimistic Mutations use?

About 3.6k tokens (SKILL.md is roughly 14k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Frontend Optimistic Mutations?

Skills that share tags, products or a category with Frontend Optimistic Mutations: Add Feature (ecency/vision-mobile, 262 stars), Theming (Code-with-Beto/skills, 140 stars), React Native Expert (tech-leads-club/agent-skills, 7k stars) and React Devtools (sanity-io/sanity, 6.4k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Frontend Optimistic Mutations?

sickn33 (a GitHub user) maintains it in sickn33/agentic-awesome-skills, which has 47,379 GitHub stars. The repository holds 1,493 skills in this directory. The repository was last updated on October 9, 2026.

Source: sickn33/agentic-awesome-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.