From 85a9cef377b60721dbcf6fde4f1ae7abc34ea959 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 20 Nov 2024 14:12:15 -0800 Subject: [PATCH] Handle Var passed to `rx.toast` If the user provides a `Var` for `message` then apply it as `props["title"]` to avoid a var operations error. --- reflex/components/sonner/toast.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reflex/components/sonner/toast.py b/reflex/components/sonner/toast.py index c7db55a40..a1b38e7e7 100644 --- a/reflex/components/sonner/toast.py +++ b/reflex/components/sonner/toast.py @@ -251,7 +251,9 @@ class Toaster(Component): "Toaster component must be created before sending a toast. (use `rx.toast.provider()`)" ) toast_command = f"{toast_ref}.{level}" if level is not None else toast_ref - if message == "" and ("title" not in props or "description" not in props): + if isinstance(message, Var): + props.setdefault("title", message) + elif message == "" and ("title" not in props and "description" not in props): raise ValueError("Toast message or title or description must be provided.") if props: args = LiteralVar.create(ToastProps(component_name="rx.toast", **props)) # type: ignore