Skip to content

Commit 3a2fabe

Browse files
authored
Merge pull request #782 from AnswerDotAI/fix/762-broken-toasts
fix broken toasts
2 parents a0467b9 + 176ad59 commit 3a2fabe

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

fasthtml/toaster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def add_toast(sess, message: str, typ: str = "info", dismiss: bool = False):
5151

5252
def render_toasts(sess):
5353
toasts = [Toast(msg, typ, dismiss, sess['toast_duration']) for msg, typ, dismiss in sess.pop(sk, [])]
54-
return Div(*toasts, hx_swap_oob=f'beforeend:#{tcid}')
54+
return Div(*toasts, id=tcid, hx_swap_oob=f'beforeend:#{tcid}')
5555

5656
def toast_after(resp, req, sess):
5757
if sk in sess and (not resp or isinstance(resp, (tuple,FT,FtResponse))):

nbs/api/00_core.ipynb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
{
132132
"data": {
133133
"text/plain": [
134-
"datetime.datetime(2025, 9, 11, 14, 0)"
134+
"datetime.datetime(2025, 9, 17, 14, 0)"
135135
]
136136
},
137137
"execution_count": null,
@@ -2879,13 +2879,13 @@
28792879
"name": "stdout",
28802880
"output_type": "stream",
28812881
"text": [
2882-
"Set to 2025-09-11 16:36:20.106162\n"
2882+
"Set to 2025-09-17 09:13:49.740165\n"
28832883
]
28842884
},
28852885
{
28862886
"data": {
28872887
"text/plain": [
2888-
"'Session time: 2025-09-11 16:36:20.106162'"
2888+
"'Session time: 2025-09-17 09:13:49.740165'"
28892889
]
28902890
},
28912891
"execution_count": null,
@@ -3109,10 +3109,29 @@
31093109
" add_toast(sess, tm, \"success\")\n",
31103110
" return P(\"I hate toast!\")\n",
31113111
"\n",
3112-
"r = cli.get('/')\n",
3113-
"assert tm in r.text\n",
31143112
"r = cli.get('/no-toast')\n",
3115-
"assert not tm in r.text"
3113+
"assert not tm in r.text\n",
3114+
"\n",
3115+
"r = cli.get('/')\n",
3116+
"assert tm in r.text"
3117+
]
3118+
},
3119+
{
3120+
"cell_type": "markdown",
3121+
"id": "bd0e4c06",
3122+
"metadata": {},
3123+
"source": [
3124+
"Here's a quick sanity check to confirm that toasts are rendered in the toast container correctly. See [issue](https://github.com/AnswerDotAI/fasthtml/issues/762)."
3125+
]
3126+
},
3127+
{
3128+
"cell_type": "code",
3129+
"execution_count": null,
3130+
"id": "e2417e5f",
3131+
"metadata": {},
3132+
"outputs": [],
3133+
"source": [
3134+
"assert 'id=\"fh-toast-container\"' in r.text"
31163135
]
31173136
},
31183137
{

0 commit comments

Comments
 (0)