Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 2 min read

Make the agent use the existing Toast, not window.alert or a homemade fixed div

The PR confirms a save with window.alert("Saved"), or it mounts a position: fixed div in the page corner with a hard-coded timeout. The repo already has a Toast or Snackbar helper with a queue, a dismiss control, and an

The PR confirms a save with window.alert("Saved"), or it mounts a position: fixed div in the page corner with a hard-coded timeout. The repo already has a Toast or Snackbar helper with a queue, a dismiss control, and an announced live region. Nearby mutations already use it. The new alert blocks the UI, and the homemade banner has a different offset, duration, and color than the rest of the product.

I've started treating a one-off success banner as a missed component, not as a lighter notification. Showing the message is the easy part. Queuing, focus, and a consistent place on screen are why the helper is there.

Why the alert or fixed div shows up

A tutorial "notify the user" example is alert() or a div and a setTimeout. The model can write that without finding toast() or useToast. Your helper may be named notify, Snackbar, or live behind a provider, which is easy to miss if the prompt only says "show a success message."

You also skip the existing variants (success, error, undo) and the rule about not stacking three banners on one action.

A simple Toast policy

  • New save, copy, and mutation feedback uses the existing Toast or Snackbar
  • Do not call window.alert or window.confirm for routine feedback
  • Do not add a one-off fixed banner in a feature file
  • A new variant or placement is a helper change, with a story

Blocking dialogs are for genuine decisions, and even then the existing confirm pattern comes first. A Toast is for a message the user can miss and still continue.

What to put in the prompt

Use the existing Toast or Snackbar helper for this success or error feedback.
Do not call window.alert, and do not build a fixed banner in this file.
Follow the existing variant, duration, and dismiss pattern.
If you need a new variant, extend the helper; do not invent a second one.

Paste one existing Toast usage. In review, search the diff for window.alert, a position: fixed banner, and a setTimeout that unmounts a one-off message.

Reject / send back

Reject

  • window.alert or window.confirm used as routine save feedback
  • A feature-level fixed banner that reimplements the Toast
  • A second toast library added for one form
  • Three stacked messages for a single action

Accept

  • Feedback that uses the existing Toast or Snackbar
  • A helper PR that adds a documented variant and a story
  • A blocking confirm that uses the existing dialog, not window.confirm
πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.