From cddb24ebd3fa14b81ea58e2035a7aa5270487416 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Sun, 2 Nov 2025 14:49:51 -0500 Subject: [PATCH] fix: check custom element tag name when rebuilding (#4413) --- tachys/src/html/element/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tachys/src/html/element/mod.rs b/tachys/src/html/element/mod.rs index 03ad87bb6..9f28146a7 100644 --- a/tachys/src/html/element/mod.rs +++ b/tachys/src/html/element/mod.rs @@ -317,6 +317,26 @@ where type State = ElementState; fn rebuild(self, state: &mut Self::State) { + // check whether the tag is the same, for custom elements + // because this is const `false` for all other element types, + // the compiler should be able to optimize it out + if E::TAG.is_empty() { + // see https://github.com/leptos-rs/leptos/issues/4412 + let new_tag = self.tag.tag(); + + // this is not particularly efficient, but it saves us from + // having to keep track of the tag name for every element state + let old_tag = state.el.tag_name(); + if new_tag != old_tag { + let mut new_state = self.build(); + state.insert_before_this(&mut new_state); + state.unmount(); + *state = new_state; + return; + } + } + + // rebuild attributes and children for any element let ElementState { attrs, children, .. } = state;