reflex-dev/reflex · error · ValueError

Title must be a single string.

Error message

Title must be a single string.

What it means

The document Title (rx.metadata.title / Title.create) must render exactly one bare string; Reflex enforces a single text child because HTML <title> cannot contain elements or multiple text nodes produced by fragments.

Source

Thrown at packages/reflex-components-core/src/reflex_components_core/base/meta.py:30

)  # for compatibility


class Title(elements.Title):
    """A component that displays the title of the current page."""

    def render(self) -> dict:
        """Render the title component.

        Returns:
            The rendered title component.

        Raises:
            ValueError: If the title is not a single string.
        """
        # Make sure the title is a single string.
        if len(self.children) != 1 or not isinstance(self.children[0], Bare):
            msg = "Title must be a single string."
            raise ValueError(msg)
        return super().render()


class Description(elements.Meta):
    """A component that displays the title of the current page."""

    name: Var[str] = field(
        default=Var.create("description"), doc="The type of the description."
    )


class Image(elements.Meta):
    """A component that displays the title of the current page."""

    property: Var[str] = field(
        default=Var.create("og:image"), doc="The type of the image."
    )

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Pass a single Python string literal: rx.title('My Page')
  2. For dynamic titles, set them via State side effects or rx.App(title=...) rather than embedding a Var
  3. Ensure only one child is provided

Example fix

// before
rx.title(State.page_title)

// after
rx.title("My Page")  # static; update dynamically via state
Defensive patterns

Strategy: validation

Validate before calling

title = "My Page"
assert isinstance(title, str)

Type guard

def is_valid_title(children) -> bool:
    return len(children) == 1 and isinstance(children[0], str)

Prevention

When it happens

Trigger: Calling Title.create with no children, multiple children, or a non-Bare child such as a Var, component, or concatenated expression, then calling render().

Common situations: Passing a State Var (Title.create(State.title)) or an f-string with Vars; adding multiple strings as separate children; forgetting the child entirely.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/30e9b51e88926f2b. Report an issue: GitHub.