mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 09:54:41 -05:00
Fixes #4248 During SSR, multiple `class` attributes were incorrectly concatenating instead of overwriting like they do in browsers. This inconsistency caused code that appeared to work in SSR to fail in CSR/hydration. The fix distinguishes between two types of class attributes: - `class="..."` attributes should overwrite (clear previous values) - `class:name=value` directives should merge (append to existing classes) Implementation: - Added `should_overwrite()` method to `IntoClass` trait (defaults to `false`) - Modified `Class::to_html()` to clear buffer before rendering if `should_overwrite()` returns `true` - Implemented `should_overwrite() -> true` for string types (`&str`, `String`, `Cow<'_, str>`, `Arc<str>`) - Tuple type `(&'static str, bool)` keeps default `false` for merge behavior Added comprehensive tests to verify: - `class="foo" class:bar=true` produces `"foo bar"` (merge) - `class:foo=true` works standalone - Correct behavior with macro attribute sorting - Global class application 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>