Skip to content

toast.promise fails to render ReactNode/JSX in success message #607

Open
@yuribmontez

Description

@yuribmontez

toast.promise fails to render ReactNode/JSX in success message

Description

When using toast.promise with JSX/ReactNode elements in the success message, the toast does not appear. However, if the JSX is removed and only a string is used, the message displays correctly. I confirmed this is a regression, as it works correctly in an older project using version 1.7.4.

Steps to reproduce

  1. Create a promise-based function
  2. Use toast.promise with JSX in the success message
  3. Observe that the success toast doesn't render

Code example

// This doesn't work - success toast with JSX doesn't appear
toast.promise(myPromise, {
  loading: <div>Loading...</div>,
  success: (data) => (
     <div>
        {data.name} <strong>worked</strong>!
      </div>
  ),
  error: 'Error',
});

// This works - success toast with string only appears
toast.promise(myPromise, {
  loading: <div>Loading...</div>,
  success: (data) => `${data.name} toast has been added`,
  error: 'Error',
});

A live reproduction is available at: https://stackblitz.com/edit/react-s5gf8aew?file=src%2FApp.js

Expected behavior

The success toast should appear regardless of whether the message is a string or a ReactNode/JSX element, as it did in version 1.2.2.

Environment

  • Sonner version: 2.0.1
  • React version: 18.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions