fasthtml
fasthtml copied to clipboard
[BUG] FtResponse breaks toasts
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
I have experienced this issue as well. Was this fixed in later versions ?
I tested this issue and noticed the following behavior:
- When I use
FtResponse(), it returns astarlette.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.
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.
Amazing! Thank you very much!! 😊