fix: issue with class hydration not removing classes correctly (closes #1286) (#1287)

This commit is contained in:
Greg Johnston 2023-07-05 12:00:27 -04:00 committed by GitHub
parent 39edb6eb45
commit 83d3d7579c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,6 +79,7 @@ pub fn class_helper(
name: Cow<'static, str>,
value: Class,
) {
use crate::HydrationCtx;
use leptos_reactive::create_render_effect;
let class_list = el.class_list();
@ -86,7 +87,9 @@ pub fn class_helper(
Class::Fn(cx, f) => {
create_render_effect(cx, move |old| {
let new = f();
if old.as_ref() != Some(&new) && (old.is_some() || new) {
if old.as_ref() != Some(&new)
&& (old.is_some() || new || HydrationCtx::is_hydrating())
{
class_expression(&class_list, &name, new, true)
}
new