Skip to content

Save and publish

.md

A button that shows work in progress, then a success mark only once the request has actually resolved, and a toast with a retry when it fails. Built from Button, StatusMorph and Toast.

Preview

Steps

  1. Guard the handler so a second activation while the request runs is ignored, and leave the busy state to StatusMorph in the button's end slot. Setting the Button `loading` as well would draw two spinners at once.
  2. Drive StatusMorph from the same status: `loading` while pending, `success` after the promise resolves, `error` after it rejects. Never set `success` before the request settles.
  3. On failure, raise an `error` toast with a `Retry` action. The action does not close the toast by itself, so dismiss it from the handler and run the request again.
  4. Let StatusMorph return to idle on its own (`resetAfter`); the button is ready for the next save without any extra state.

Pitfalls

  • Showing success optimistically: if the request then fails, the interface has already told the user the work is saved.
  • Disabling the button while loading: it drops focus and hides the busy state from assistive technology. Keep it enabled and guard the handler instead.
  • Leaving the error toast to time out: it carries the only way to retry, so it should stay until the user acts or closes it.

Components used