reflex-dev/reflex · error · ValueError
f"Invalid variant: {variant}. Available variants: {available
Error message
f"Invalid variant: {variant}. Available variants: {available_variants}" What it means
Link validates its variant the same way Button does; only variants registered in LINK_VARIANTS (classic, solid, soft, surface, outline, ghost) are accepted.
Source
Thrown at packages/reflex-components-internal/src/reflex_components_internal/components/base/link.py:95
class_name = cn(
f"{ClassNames.ROOT} {size_class} {variant_class}", link_class_name
)
if show_icon:
children.append(hi("LinkSquare02Icon", class_name=ClassNames.ICON))
props["class_name"] = class_name
return super().create(*children, **props)
@staticmethod
def validate_variant(variant: LiteralLinkVariant):
"""Validate the link variant."""
if variant not in LINK_VARIANTS["variant"]:
available_variants = ", ".join(LINK_VARIANTS["variant"].keys())
message = (
f"Invalid variant: {variant}. Available variants: {available_variants}"
)
raise ValueError(message)
@staticmethod
def validate_size(size: LiteralLinkSize):
"""Validate the link size."""
if size not in LINK_VARIANTS["size"]:
available_sizes = ", ".join(LINK_VARIANTS["size"].keys())
message = f"Invalid size: {size}. Available sizes: {available_sizes}"
raise ValueError(message)
def _exclude_props(self) -> list[str]:
return [*super()._exclude_props(), "size", "variant", "show_icon", "render_"]
link = Link.create
View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Use a variant listed in the error (e.g. "solid", "soft", "outline")
- Drop variant and style via css/class_name for effects like underline
- Map legacy names during migration
Example fix
# before
rx.link("Home", href="/", variant="unstyled")
# after
rx.link("Home", href="/", variant="ghost") Defensive patterns
Strategy: validation
Validate before calling
from reflex_components_internal.components.base.link import LINK_VARIANTS
if variant not in LINK_VARIANTS['variant']:
variant = 'ghost' Type guard
def is_valid_link_variant(v: str) -> TypeGuard[str]:
from reflex_components_internal.components.base.link import LINK_VARIANTS
return v in LINK_VARIANTS['variant'] Prevention
- Use listed link variants only
- Use css/class_name for effects like underline
When it happens
Trigger: rx.link("docs", href="#", variant="underline") or any Chakra-era variant like "unstyled".
Common situations: Migrating from reflex.components.radix or Chakra links; copying variant names from other component libraries.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- f"Invalid variant: {variant}. Available variants: {available
- f"Invalid size: {size}. Available sizes: {available_sizes}"
- Link without a child will not display
- ChildrenTypeError(component=cls.__name__, child=child)
- Do not override _add_style directly. Use add_style instead.
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/9a7c61e025fb8ba1.
Report an issue: GitHub.