docs: warn if you are using leptos_meta without features (#797)

This commit is contained in:
Greg Johnston 2023-04-03 21:07:43 -04:00 committed by GitHub
parent db9b7db53d
commit 64e056ffa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View file

@ -83,6 +83,9 @@ pub fn Body(
#[prop(optional, into)]
attributes: Option<MaybeSignal<AdditionalAttributes>>,
) -> impl IntoView {
#[cfg(debug_assertions)]
crate::feature_warning();
cfg_if! {
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
let el = document().body().expect("there to be a <body> element");

View file

@ -98,6 +98,9 @@ pub fn Html(
#[prop(optional, into)]
attributes: Option<MaybeSignal<AdditionalAttributes>>,
) -> impl IntoView {
#[cfg(debug_assertions)]
crate::feature_warning();
cfg_if! {
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
let el = document().document_element().expect("there to be a <html> element");

View file

@ -206,6 +206,9 @@ pub fn provide_meta_context(cx: Scope) {
/// call `use_head()` but a single [MetaContext] has not been provided at the application root.
/// The best practice is always to call [provide_meta_context] early in the application.
pub fn use_head(cx: Scope) -> MetaContext {
#[cfg(debug_assertions)]
feature_warning();
match use_context::<MetaContext>(cx) {
None => {
debug_warn!(
@ -343,3 +346,10 @@ where
TextProp(Rc::new(s))
}
}
#[cfg(debug_assertions)]
pub(crate) fn feature_warning() {
if !cfg!(any(feature = "csr", feature = "hydrate", feature = "ssr")) {
leptos::debug_warn!("WARNING: `leptos_meta` does nothing unless you enable one of its features (`csr`, `hydrate`, or `ssr`). See the docs at https://docs.rs/leptos_meta/latest/leptos_meta/ for more information.");
}
}