docs: add some missing `#[must_use]` to avoid accidental `()` rendering (#1885)

This commit is contained in:
Greg Johnston 2023-10-11 15:00:27 -04:00 committed by GitHub
parent 971fb734de
commit c6f51e6a09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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>,

View File

@ -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<El: ElementDescriptor> {
#[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<El: ElementDescriptor> {
pub(crate) element: El,