{"record":{"id":"e585fe93c4c77af9","repo":"yewstack/yew","slug":"missing-condition-for-if-expression","errorCode":null,"errorMessage":"missing condition for `if` expression","messagePattern":"missing condition for `if` expression","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-macro/src/html_tree/html_if.rs","lineNumber":31,"sourceCode":"    cond: Box<Expr>,\n    then_branch: HtmlRootBraced,\n    else_branch: Option<(Token![else], Box<HtmlRootBracedOrIf>)>,\n}\n\nimpl PeekValue<()> for HtmlIf {\n    fn peek(cursor: Cursor) -> Option<()> {\n        let (ident, _) = cursor.ident()?;\n        (ident == \"if\").then_some(())\n    }\n}\n\nimpl Parse for HtmlIf {\n    fn parse(input: ParseStream) -> syn::Result<Self> {\n        let if_token = input.parse()?;\n        let cond = Box::new(input.call(Expr::parse_without_eager_brace)?);\n        match &*cond {\n            Expr::Block(syn::ExprBlock { block, .. }) if block.stmts.is_empty() => {\n                return Err(syn::Error::new(\n                    cond.span(),\n                    \"missing condition for `if` expression\",\n                ));\n            }\n            _ => {}\n        }\n        if input.is_empty() {\n            return Err(syn::Error::new(\n                cond.span(),\n                \"this `if` expression has a condition, but no block\",\n            ));\n        }\n\n        let then_branch = input.parse()?;\n        let else_branch = input\n            .parse::<Token![else]>()\n            .ok()\n            .map(|else_token| {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-macro/src/html_tree/html_if.rs#L13-L49","documentation":"`HtmlIf::parse` reads the `if` token and then parses the condition with `Expr::parse_without_eager_brace` (html_if.rs:29). If the parsed condition is an empty block `{}`, there was never a real condition before the then-block, so the macro errors on the condition's span. Because `html!` children are brace-delimited, `if {} {…}` looks plausible but leaves the if with nothing to test.","triggerScenarios":"`html! { if {} { <p/> } }` — the token immediately after `if` is an empty block instead of a boolean expression.","commonSituations":"Leaving an IDE snippet placeholder `{}` after `if`, intending the block as a grouping wrapper (like a React fragment), or deleting a condition while editing a template.","solutions":["Write a real condition before the then-block: `if is_ready { … }`","If you only wanted to group children, use a fragment `<></>` instead of an empty `if`","Bind complex conditions to a named `bool` above the macro and reference that identifier"],"exampleFix":"// before\nhtml! { if {} { <p>{ \"never compiles\" }</p> } }\n\n// after\nhtml! { if is_ready { <p>{ \"ready\" }</p> } }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always type a boolean expression after `if` in `html!`; if grouping was the goal, use `<></>`","Replace IDE snippet placeholders before compiling","Compute complex conditions as named `bool`s in plain Rust so the template line stays short and obviously conditioned"],"tags":["rust","yew","html-macro","if-expression","syntax"],"backgroundTag":"incomplete-if-expression","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}