{"record":{"id":"80d77c4783ddf078","repo":"reflex-dev/reflex","slug":"match-children-count-mismatch-expected-num-cases","errorCode":null,"errorMessage":"Match children count mismatch: expected {num_cases + 1} (cases + default), got {len(self.children)}","messagePattern":"Match children count mismatch: expected (.+?) \\(cases \\+ default\\), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/match.py","lineNumber":287,"sourceCode":"    def _render(self) -> Tag:\n        # Reconstruct match_cases and default from self.children, which may have\n        # been updated by the compiler walker to include memoized wrappers.\n        # self.children contains: [case_1_return, case_2_return, ..., default]\n        # self.match_cases contains the conditions as Vars.\n        num_cases = len(self.match_cases)\n        children_var = passthrough_children_var(self.children)\n        if children_var is not None:\n            # Auto-memo passthrough body: index into the placeholder array so\n            # branch JSX stays on the page side.\n            cases_returns = [Bare.create(children_var[i]) for i in range(num_cases)]\n            default_return = Bare.create(children_var[num_cases])\n        else:\n            if len(self.children) != num_cases + 1:\n                msg = (\n                    f\"Match children count mismatch: expected {num_cases + 1} \"\n                    f\"(cases + default), got {len(self.children)}\"\n                )\n                raise ValueError(msg)\n\n            cases_returns = self.children[:num_cases]\n            default_return = self.children[num_cases]\n\n        return MatchTag(\n            cond=str(self.cond),\n            match_cases=[\n                ([str(cond) for cond in conditions], return_value.render())\n                for (conditions, _), return_value in zip(\n                    self.match_cases,\n                    cases_returns,\n                    strict=True,\n                )\n            ],\n            default=default_return.render(),\n        )\n\n    def render(self) -> dict:","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/match.py#L269-L305","documentation":"The Match component internally builds one child per case plus a default. At render time the children count must equal num_cases + 1; a mismatch means the component tree was mutated or constructed inconsistently (e.g. children added/removed after create).","triggerScenarios":"Manually appending/removing children on a rx.match component instance after creation, or subclassing Match and overriding create in a way that desynchronizes match_cases from children.","commonSituations":"Framework-level bug or manual manipulation of Match.children; not typically produced by normal declarative usage of rx.match.","solutions":["Don't mutate a Match component's children after creation; rebuild it via rx.match(...) with the full case list","Ensure the default value is passed so the default child exists","If subclassing Match, keep match_cases and children in sync (one child per case plus default)","If unreachable via public API, report as a Reflex framework bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    rendered = match_comp.render()\nexcept ValueError as e:\n    if 'children count mismatch' in str(e):\n        match_comp = rx.match(...)  # rebuild from scratch\n    else:\n        raise","preventionTips":["Never mutate Match.children after creation","Rebuild rx.match with a new case list instead of editing children"],"tags":["reflex","match","internal-invariant"],"backgroundTag":"component-state-invariant-violation","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}