fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

[BUG] FtResponse breaks toasts

Open jsandeo opened this issue 1 year ago • 2 comments

Describe the bug Wrapping the response with FtResponse() apparently breaks toasts, meaning the toast won't show in the browser.

Minimal Reproducible Example

from fasthtml.common import *

app, rt = fast_app(hdrs=(picolink,))
setup_toasts(app)

@rt("/")
def get(sess):
  add_toast(sess, 'This toast will show!', 'success')
  return Div('Aloha!')

@rt("/notoast")
def get(sess):
  add_toast(sess, 'This toast won\'t show!', 'success')
  return FtResponse(Div('Aloha!'))

serve()

Expected behavior Toasts should show in the browser.

Environment Information Please provide the following version information:

  • fastlite version: 0.0.10
  • fastcore version: 1.7.9
  • fasthtml version: 0.6.9

Confirmation Please confirm the following:

  • [✓] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
  • [✓] I have provided a minimal reproducible example
  • [✓] I have included the versions of fastlite, fastcore, and fasthtml
  • [✓] I understand that this is a volunteer open source project with no commercial support.

Additional context I used FtResponse() so I could set a non-200 status_code for the response (such as 422 for a form POST having validation errors), maybe there is a simpler way to do just that... but I guess toasts should work anyway when using FtResponse().

Screenshots toast notoast

jsandeo avatar Oct 01 '24 15:10 jsandeo

I have experienced this issue as well. Was this fixed in later versions ?

seekerquest avatar Jul 04 '25 04:07 seekerquest

I tested this issue and noticed the following behavior:

  • When I use FtResponse(), it returns a starlette.responses.HTMLResponse object at 0x79d9d1ae6660> without any response data, but the toast still works.
  • When I remove add_toast(), the response data is returned correctly, but the toast does not appear.

Tested in versions:

  • fasthtml: 0.12.28
  • fastlite: 0.1.4
  • fastcore: 1.8.2

See: https://fasthtml-test-toaster.vercel.app/ for some examples.

78wesley avatar Sep 19 '25 12:09 78wesley

This has been fixed! Both toasts now work correctly, whether using FtResponse or not.

The fix was merged in PR #526 (Allow toasts to work with FtResponse) and there was an additional fix in PR #782.

Tested on current main and both routes show toasts as expected.

erikgaas avatar Dec 03 '25 04:12 erikgaas

Amazing! Thank you very much!! 😊

seekerquest avatar Dec 03 '25 04:12 seekerquest