Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yuribmontez opened this issue Mar 21, 2025 · 0 comments
Open

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

yuribmontez opened this issue Mar 21, 2025 · 0 comments

Comments

@yuribmontez
Copy link

yuribmontez commented Mar 21, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant