{"record":{"id":"bca3fee060511400","repo":"reflex-dev/reflex","slug":"match-condition-condition-index-of-case-case-in","errorCode":null,"errorMessage":"Match condition {condition_index} of case {case_index} cannot be a component.","messagePattern":"Match condition (.+?) of case (.+?) cannot be a component\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/match.py","lineNumber":167,"sourceCode":"            The processed match cases.\n\n        Raises:\n            ValueError: If the default case is not the last case or the tuple elements are less than 2.\n        \"\"\"\n        match_cases: list[tuple[list[Var], BaseComponent | Var]] = []\n        for case_index, case in enumerate(cases):\n            # There should be at least two elements in a case tuple(a condition and return value)\n            if len(case) < 2:\n                msg = \"A case tuple should have at least a match case element and a return value.\"\n                raise ValueError(msg)\n\n            *conditions, return_value = case\n\n            conditions_vars: list[Var] = []\n            for condition_index, condition in enumerate(conditions):\n                if isinstance(condition, BaseComponent):\n                    msg = f\"Match condition {condition_index} of case {case_index} cannot be a component.\"\n                    raise ValueError(msg)\n                conditions_vars.append(cls._create_case_var_with_var_data(condition))\n\n            return_value = (\n                cls._create_case_var_with_var_data(return_value)\n                if not isinstance(return_value, BaseComponent)\n                else return_value\n            )\n\n            if not isinstance(return_value, (Var, BaseComponent)):\n                msg = \"Return value must be a var or component\"\n                raise ValueError(msg)\n\n            match_cases.append((conditions_vars, return_value))\n\n        return match_cases\n\n    @classmethod\n    def _validate_return_types(","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/match.py#L149-L185","documentation":"In rx.match, conditions (all tuple elements except the last) must be vars or values convertible to vars, not components. Components are only allowed as the return value (last element) of a case.","triggerScenarios":"Passing a component as a non-final tuple element, e.g. rx.match(cond, (rx.text(\"a\"), rx.text(\"b\"))) where the first rx.text is treated as a condition rather than a return value.","commonSituations":"Miscounting tuple positions: intending (return_value, condition) order, or forgetting that only the last element is the return value when a case has one condition.","solutions":["Reorder so the component is the last element: (condition, component_return_value)","If the condition must render something, compute it as a var (e.g. a computed var or expression) instead of a component"],"exampleFix":"# before\nrx.match(State.n, (rx.text(\"one\"), 1))\n# after\nrx.match(State.n, (1, rx.text(\"one\")))","handlingStrategy":"validation","validationCode":"from reflex.components.base.bare import Bare\nfrom reflex.components import Component\n\nconditions = case[:-1]\nassert not any(isinstance(c, Component) for c in conditions), 'conditions cannot be components'","typeGuard":"def has_component_condition(case: tuple) -> bool:\n    return any(isinstance(c, Component) for c in case[:-1])","tryCatchPattern":null,"preventionTips":["Remember only the LAST tuple element is the return value","Components belong at the end of the case tuple"],"tags":["reflex","match","component-misuse"],"backgroundTag":"invalid-argument-shape","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}