fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

[BUG] FtResponse breaks toasts

Open jsandeo opened this issue 4 months ago • 0 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