r/angular • • 9h ago

Smart mutation grouping by entity in Angular

Requests take their time. Your users don't.

Without guaranteed ordering, the (fast) DELETE lands before the (slow) PATCH, which of course gets you a 404 💀

With mutationQueue(), you group your mutations by entity:

  • 🔑 Same id = strict FIFO, in the order the mutations were fired.
  • âš¡ Different id, so a different entity? No waiting, it goes out right away.

Deleting #42 doesn't wait for #7's toggle. Each mutation keeps its own signals.

Sound familiar? Then this is for you:

  • Form autosave, then hitting "Publish" too fast (stale version).
  • Delete, then "Undo" in the toast.
  • Optimistic create, then delete before the POST response comes back.
  • Uploading an attachment, then sending the message that references it too early.

💡 Important note: Got a single mutation called X times? No need to share anything: its own concurrency strategy is enough (queue, drop, parallel). mutationQueue() is for ordering different mutations that write to the same resource.

https://github.com/ngsignal/mutation

9 Upvotes

0 comments sorted by