Skip to content

Commit

Permalink
docs: add some missing #[must_use] to avoid accidental () renderi…
Browse files Browse the repository at this point in the history
…ng (#1885)
  • Loading branch information
gbj authored Oct 11, 2023
1 parent 971fb73 commit c6f51e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions leptos_dom/src/components/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HydrationKey>,
Expand Down
9 changes: 9 additions & 0 deletions leptos_dom/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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<El: ElementDescriptor> {
#[cfg(debug_assertions)]
Expand All @@ -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<El: ElementDescriptor> {
pub(crate) element: El,
Expand Down

0 comments on commit c6f51e6

Please sign in to comment.