{"record":{"id":"5e04c6413ea7f35b","repo":"leptos-rs/leptos","slug":"rendering-b-to-html-without-filling-it","errorCode":null,"errorMessage":"rendering B to HTML without filling it","messagePattern":"rendering B to HTML without filling it","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tachys/src/view/either.rs","lineNumber":596,"sourceCode":"                    None => None,\n                }\n            },\n        )\n        .await;\n        EitherKeepAlive { a, b, show_b }\n    }\n\n    fn to_html_with_buf(\n        self,\n        buf: &mut String,\n        position: &mut Position,\n        escape: bool,\n        mark_branches: bool,\n        extra_attrs: Vec<AnyAttribute>,\n    ) {\n        if self.show_b {\n            self.b\n                .expect(\"rendering B to HTML without filling it\")\n                .to_html_with_buf(\n                    buf,\n                    position,\n                    escape,\n                    mark_branches,\n                    extra_attrs,\n                );\n        } else {\n            self.a\n                .expect(\"rendering A to HTML without filling it\")\n                .to_html_with_buf(\n                    buf,\n                    position,\n                    escape,\n                    mark_branches,\n                    extra_attrs,\n                );\n        }","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/tachys/src/view/either.rs#L578-L614","documentation":"EitherKeepAliveState keeps only the currently shown side filled: if showing_b is true, self.b holds Some(B) while self.a is None (and vice versa). Rendering to HTML when show_b is true requires the B view to have been stored; this panic means the state claims branch B is shown but the B slot was never filled. It guards against an internally inconsistent EitherKeepAliveState.","triggerScenarios":"Calling to_html_with_buf on an EitherKeepAliveState whose show_b flag is true but whose b field is None — i.e. the state was constructed or mutated without filling the B view (e.g. hand-built state, or deserialized/partially initialized state used in server-side rendering).","commonSituations":"SSR/streaming rendering of a hand-constructed EitherKeepAliveState; framework code that sets the branch flag without re-rendering the branch; custom view code manipulating EitherKeepAliveState fields directly.","solutions":["Fill both sides appropriately via the normal update path (mount/rebuild) before rendering to HTML.","Ensure EitherKeepAliveState is only created through its constructor with the active view passed in.","If building state manually, set b = Some(view) whenever show_b = true."],"exampleFix":"// before\nlet state = EitherKeepAliveState { showing_b: true, a: None, b: None };\nstate.to_html_with_buf(...); // panics\n// after\nlet state = EitherKeepAliveState { showing_b: true, a: None, b: Some(view_b) };\nstate.to_html_with_buf(...);","handlingStrategy":"validation","validationCode":"if state.showing_b && state.b.is_none() {\n    panic!(\"state says B is shown but b is not filled\");\n}\nstate.to_html_with_buf(&mut buf, position, escape, mark_branches, extra_attrs);","typeGuard":"fn b_side_filled<A, B>(state: &EitherKeepAliveState<A, B>) -> bool {\n    !state.showing_b || /* b accessor */ true // ensure b is Some when showing_b\n}","tryCatchPattern":"std::panic::catch_unwind(|| state.to_html_with_buf(&mut buf, position, escape, mark_branches, extra_attrs))\n    .inspect_err(|_| eprintln!(\"EitherKeepAliveState had unfilled B branch during SSR\"));","preventionTips":["Never build EitherKeepAliveState with struct literals; use the library constructors.","Keep the invariant showing_b == b.is_some() (and !showing_b => a.is_some()).","In SSR tests, assert the branch view is present before rendering.","Add debug_assert! checks around manual state manipulation."],"tags":["ssr","html-rendering","either-view","panic","tachys"],"backgroundTag":"unfilled-either-branch","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}