Summary
Passing a State Var as title or description to @rx.page raises VarTypeError. The same failure can occur later at compile time in add_meta() when description is a Var.
Error
reflex_base.utils.exceptions.VarTypeError: Cannot convert Var '…' to bool
for use with `if`, `and`, `or`, and `not`. Instead use `rx.cond` and
bitwise operators `&` (and), `|` (or), `~` (invert).
Affected locations
1. reflex/page.py (@rx.page decorator)
if title:
kwargs["title"] = title
if description:
kwargs["description"] = description
Any non-None Var hits Var.__bool__ and raises immediately when the decorator runs.
2. reflex/compiler/utils.py (add_meta)
children: list[Any] = [Title.create(title)]
if description:
children.append(Description.create(content=description))
If a Var description reaches the compiler, compilation fails here.
Expected behavior
title and description should accept str | Var | None consistently for both @rx.page and app.add_page, matching the documented page metadata API for dynamic SEO titles and descriptions (especially on dynamic routes).
Suggested fix
Replace truthiness checks with explicit None checks:
# reflex/page.py
if title is not None:
kwargs["title"] = title
if description is not None:
kwargs["description"] = description
# reflex/compiler/utils.py (add_meta)
if description is not None:
children.append(Description.create(content=description))
Optionally tighten type annotations to str | Var | None where appropriate.
Minimal reproduction
import reflex as rx
class State(rx.State):
page_title: str = "Hello"
page_description: str = "A dynamic description"
@rx.page(
route="/",
title=State.page_title, # raises VarTypeError in page.py
description=State.page_description, # raises VarTypeError in page.py
)
def index():
return rx.text("Hi")
app = rx.App()
Environment
- Reflex: 0.9.4 (also present in 0.9.8 source for both files)
- Python: 3.13
Impact
Dynamic per-page titles and descriptions for SEO cannot be set reliably with State vars through @rx.page.
Summary
Passing a State
Varastitleordescriptionto@rx.pageraisesVarTypeError. The same failure can occur later at compile time inadd_meta()whendescriptionis aVar.Error
Affected locations
1.
reflex/page.py(@rx.pagedecorator)Any non-
NoneVarhitsVar.__bool__and raises immediately when the decorator runs.2.
reflex/compiler/utils.py(add_meta)If a
Vardescription reaches the compiler, compilation fails here.Expected behavior
titleanddescriptionshould acceptstr | Var | Noneconsistently for both@rx.pageandapp.add_page, matching the documented page metadata API for dynamic SEO titles and descriptions (especially on dynamic routes).Suggested fix
Replace truthiness checks with explicit
Nonechecks:Optionally tighten type annotations to
str | Var | Nonewhere appropriate.Minimal reproduction
Environment
Impact
Dynamic per-page titles and descriptions for SEO cannot be set reliably with State vars through
@rx.page.