reflex-dev/reflex · error · ValueError
Match children count mismatch: expected {num_cases + 1} (cas
Error message
Match children count mismatch: expected {num_cases + 1} (cases + default), got {len(self.children)} What it means
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).
Source
Thrown at packages/reflex-components-core/src/reflex_components_core/core/match.py:287
def _render(self) -> Tag:
# Reconstruct match_cases and default from self.children, which may have
# been updated by the compiler walker to include memoized wrappers.
# self.children contains: [case_1_return, case_2_return, ..., default]
# self.match_cases contains the conditions as Vars.
num_cases = len(self.match_cases)
children_var = passthrough_children_var(self.children)
if children_var is not None:
# Auto-memo passthrough body: index into the placeholder array so
# branch JSX stays on the page side.
cases_returns = [Bare.create(children_var[i]) for i in range(num_cases)]
default_return = Bare.create(children_var[num_cases])
else:
if len(self.children) != num_cases + 1:
msg = (
f"Match children count mismatch: expected {num_cases + 1} "
f"(cases + default), got {len(self.children)}"
)
raise ValueError(msg)
cases_returns = self.children[:num_cases]
default_return = self.children[num_cases]
return MatchTag(
cond=str(self.cond),
match_cases=[
([str(cond) for cond in conditions], return_value.render())
for (conditions, _), return_value in zip(
self.match_cases,
cases_returns,
strict=True,
)
],
default=default_return.render(),
)
def render(self) -> dict:View on GitHub (pinned to 45b8ed5ab7)
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
Defensive patterns
Strategy: try-catch
Try / catch
try:
rendered = match_comp.render()
except ValueError as e:
if 'children count mismatch' in str(e):
match_comp = rx.match(...) # rebuild from scratch
else:
raise Prevention
- Never mutate Match.children after creation
- Rebuild rx.match with a new case list instead of editing children
When it happens
Trigger: 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.
Common situations: Framework-level bug or manual manipulation of Match.children; not typically produced by normal declarative usage of rx.match.
Related errors
- For cases with return types as Vars, a default case must be
- The condition must be set
- rx.match should have at least one case.
- rx.match should have tuples of cases and one default case as
- A case tuple should have at least a match case element and a
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/80d77c4783ddf078.
Report an issue: GitHub.