From 935da60d8d8755add92b1aa7745e76f8d83a68f7 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Wed, 11 Oct 2023 11:53:18 -0400 Subject: [PATCH] docs: add some missing `#[must_use]` to avoid accidental `()` rendering --- leptos_dom/src/components/fragment.rs | 3 +++ leptos_dom/src/html.rs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/leptos_dom/src/components/fragment.rs b/leptos_dom/src/components/fragment.rs index 007a399b15..6ff42416d2 100644 --- a/leptos_dom/src/components/fragment.rs +++ b/leptos_dom/src/components/fragment.rs @@ -23,6 +23,9 @@ where } /// Represents a group of [`views`](View). +#[must_use = "You are creating a Fragment but not using it. An unused view can \ + cause your view to be rendered as () unexpectedly, and it can \ + also cause issues with client-side hydration."] #[derive(Debug, Clone)] pub struct Fragment { id: Option, diff --git a/leptos_dom/src/html.rs b/leptos_dom/src/html.rs index 46d2ef409e..0067c8a219 100644 --- a/leptos_dom/src/html.rs +++ b/leptos_dom/src/html.rs @@ -128,6 +128,9 @@ where } /// Represents potentially any element. +#[must_use = "You are creating AnyElement but not using it. An unused view can \ + cause your view to be rendered as () unexpectedly, and it can \ + also cause issues with client-side hydration."] #[derive(Clone, Debug)] pub struct AnyElement { pub(crate) name: Oco<'static, str>, @@ -272,6 +275,9 @@ impl ElementDescriptor for Custom { cfg_if! { if #[cfg(all(target_arch = "wasm32", feature = "web"))] { /// Represents an HTML element. + #[must_use = "You are creating an HtmlElement<_> but not using it. An unused view can \ + cause your view to be rendered as () unexpectedly, and it can \ + also cause issues with client-side hydration."] #[derive(Clone)] pub struct HtmlElement { #[cfg(debug_assertions)] @@ -283,6 +289,9 @@ cfg_if! { // Server needs to build a virtualized DOM tree } else { /// Represents an HTML element. + #[must_use = "You are creating an HtmlElement<_> but not using it. An unused view can \ + cause your view to be rendered as () unexpectedly, and it can \ + also cause issues with client-side hydration."] #[derive(Clone)] pub struct HtmlElement { pub(crate) element: El,