{"record":{"id":"7fd704dbfa35aaa0","repo":"yewstack/yew","slug":"missing-condition-for-while-expression","errorCode":null,"errorMessage":"missing condition for `while` expression","messagePattern":"missing condition for `while` expression","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"packages/yew-macro/src/html_tree/html_while.rs","lineNumber":33,"sourceCode":"    stmts: Vec<Stmt>,\n    body: HtmlChildrenTree,\n    deprecations: TokenStream,\n}\n\nimpl PeekValue<()> for HtmlWhile {\n    fn peek(cursor: Cursor) -> Option<()> {\n        let (ident, _) = cursor.ident()?;\n        (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","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/yewstack/yew/blob/0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3/packages/yew-macro/src/html_tree/html_while.rs#L15-L51","documentation":"`HtmlWhile::parse` parses the `while` token and then the condition via `Expr::parse_without_eager_brace` (html_while.rs:30-31); if the parsed condition is an empty block `{}`, no condition was written and the macro errors on the condition span (html_while.rs:32-38). It is the same guard the `if` variant applies, extended to `while` loops in `html!`.","triggerScenarios":"`html! { while {} { <Spinner /> } }` — an empty block between `while` and the loop body instead of a boolean expression.","commonSituations":"A placeholder condition left by a snippet, intending `{}` as a grouping block, or editing away the real condition and leaving the braces behind.","solutions":["Write the loop condition: `while loading { … }`","If the condition is dynamic, compute a `bool` before `html!` and use that identifier in the loop","For unconditional repetition use `for _ in 0..n` instead"],"exampleFix":"// before\nhtml! { while {} { <Spinner /> } }\n\n// after\nhtml! { while loading { <Spinner /> } }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always follow `while` in `html!` with a boolean expression, then the body block","Compute dynamic conditions as named `bool`s before the macro","Prefer `for _ in 0..n` for unconditional repetition"],"tags":["rust","yew","html-macro","while-loop","syntax"],"backgroundTag":"incomplete-while-loop","analyzedSha":"0e4a05472fac4e5fce1befe60fa4a1e43a36b6a3","analyzedAt":"2026-08-22T21:16:31.212Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}