Skip to content

Commit 190d272

Browse files
authored
Merge pull request #526 from tomasz-pankowski/Toast-With-FtResponse
Allow toasts to work with FtResponse
2 parents 4048bd2 + 36f8009 commit 190d272

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

fasthtml/toaster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def render_toasts(sess):
5151
hx_swap_oob="afterbegin:body")
5252

5353
def toast_after(resp, req, sess):
54-
if sk in sess and (not resp or isinstance(resp, (tuple,FT))): req.injects.append(render_toasts(sess))
54+
if sk in sess and (not resp or isinstance(resp, (tuple,FT,FtResponse))): req.injects.append(render_toasts(sess))
5555

5656
def setup_toasts(app):
5757
app.hdrs += (Style(toast_css), Script(toast_js, type="module"))

nbs/tutorials/quickstart_for_web_devs.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@
12801280
"\n",
12811281
"1. `setup_toasts` is a helper function that adds toast dependencies. Usually this would be declared right after `fast_app()`\n",
12821282
"2. Toasts require sessions\n",
1283-
"3. Views with Toasts must return FT components."
1283+
"3. Views with Toasts must return FT or FtResponse components."
12841284
]
12851285
},
12861286
{

tests/test_toaster.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def post(session):
1919
def get(session):
2020
return Titled("Hello, world!", P(str(session)))
2121

22+
@rt("/see-toast-ft-response")
23+
def get(session):
24+
add_toast(session, "Toast FtResponse", "info")
25+
return FtResponse(Titled("Hello, world!", P(str(session))))
26+
2227
def test_get_toaster():
2328
cli.get('/set-toast-get', follow_redirects=False)
2429
res = cli.get('/see-toast')
@@ -32,6 +37,11 @@ def test_post_toaster():
3237
res = cli.get('/see-toast')
3338
assert 'Toast post' in res.text
3439

40+
def test_ft_response():
41+
res = cli.get('/see-toast-ft-response')
42+
assert 'Toast FtResponse' in res.text
43+
3544
test_get_toaster()
3645
test_post_toaster()
46+
test_ft_response()
3747

0 commit comments

Comments
 (0)