{"record":{"id":"6b2803058e075c71","repo":"yewstack/yew","slug":"this-while-expression-has-a-condition-but-no-bl","errorCode":null,"errorMessage":"this `while` expression has a condition, but no block","messagePattern":"this `while` expression has a condition, but no block","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-macro/src/html_tree/html_while.rs","lineNumber":41,"sourceCode":"        (ident == \"while\").then_some(())\n    }\n}\n\nimpl Parse for HtmlWhile {\n    fn parse(input: ParseStream) -> syn::Result<Self> {\n        While::parse(input)?;\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 `while` expression\",\n                ));\n            }\n            _ => {}\n        }\n        if input.is_empty() {\n            return Err(syn::Error::new(\n                cond.span(),\n                \"this `while` expression has a condition, but no block\",\n            ));\n        }\n\n        let body_stream;\n        braced!(body_stream in input);\n\n        let (stmts, body, deprecations) = parse_loop_body(&body_stream, \"while\")?;\n\n        Ok(Self {\n            cond,\n            stmts,\n            body,\n            deprecations,\n        })\n    }\n}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-macro/src/html_tree/html_while.rs#L23-L59","documentation":"After parsing the condition, `HtmlWhile::parse` checks `input.is_empty()` (html_while.rs:39-45); if the input ends immediately after the condition, the required brace-delimited body is missing and the error points at the condition span. `while` inside `html!` must always carry its `{ … }` body, just like plain Rust.","triggerScenarios":"`html! { while loading }` — a condition present but nothing after it (end of macro input).","commonSituations":"Truncated templates while sketching loading spinners, forgetting the body block, or expecting following sibling children to serve as the body without braces.","solutions":["Add the body block: `while loading { <Spinner /> }`","Compute repeated children in plain Rust and render the result once","Double-check the construct — for a one-shot conditional, `if` is likely what was meant"],"exampleFix":"// before\nhtml! { while loading }\n\n// after\nhtml! { while loading { <Spinner /> } }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write the `{ … }` body in the same edit as the `while` condition","Double-check whether `if` was intended — one-shot conditionals are the common mix-up","Render the loop body from a plain Rust loop into a `Vec<VNode>` when the template gets unwieldy"],"tags":["rust","yew","html-macro","while-loop","syntax","missing-block"],"backgroundTag":"incomplete-while-loop","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}