mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-28 07:52:34 -05:00
Compare commits
2 Commits
1408
...
meta-tag-h
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa952f214e | ||
|
|
6abc4695a9 |
@@ -8,6 +8,7 @@ cfg_if! {
|
||||
use crate::macro_helpers::*;
|
||||
use crate::{mount_child, MountKind};
|
||||
use once_cell::unsync::Lazy as LazyCell;
|
||||
use std::cell::Cell;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
/// Trait alias for the trait bounts on [`ElementDescriptor`].
|
||||
@@ -20,6 +21,22 @@ cfg_if! {
|
||||
El: fmt::Debug + AsRef<web_sys::HtmlElement> + Clone
|
||||
{
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static IS_META: Cell<bool> = Cell::new(false);
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn as_meta_tag<T>(f: impl FnOnce() -> T) -> T {
|
||||
IS_META.with(|m| m.set(true));
|
||||
let v = f();
|
||||
IS_META.with(|m| m.set(false));
|
||||
v
|
||||
}
|
||||
|
||||
fn is_meta_tag() -> bool {
|
||||
IS_META.with(|m| m.get())
|
||||
}
|
||||
} else {
|
||||
use crate::hydration::HydrationKey;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
@@ -35,6 +52,11 @@ cfg_if! {
|
||||
pub trait ElementDescriptorBounds: fmt::Debug {}
|
||||
|
||||
impl<El> ElementDescriptorBounds for El where El: fmt::Debug {}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn as_meta_tag<T>(f: impl FnOnce() -> T) -> T {
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,9 +227,12 @@ impl Custom {
|
||||
|
||||
el.unchecked_into()
|
||||
} else {
|
||||
crate::warn!(
|
||||
"element with id {id} not found, ignoring it for hydration"
|
||||
);
|
||||
if !is_meta_tag() {
|
||||
crate::warn!(
|
||||
"element with id {id} not found, ignoring it for \
|
||||
hydration"
|
||||
);
|
||||
}
|
||||
|
||||
crate::document().create_element(&name).unwrap()
|
||||
}
|
||||
@@ -993,9 +1018,11 @@ fn create_leptos_element(
|
||||
|
||||
el.unchecked_into()
|
||||
} else {
|
||||
crate::warn!(
|
||||
"element with id {id} not found, ignoring it for hydration"
|
||||
);
|
||||
if !is_meta_tag() {
|
||||
crate::warn!(
|
||||
"element with id {id} not found, ignoring it for hydration"
|
||||
);
|
||||
}
|
||||
|
||||
clone_element()
|
||||
}
|
||||
|
||||
@@ -85,25 +85,30 @@ pub fn Link(
|
||||
let next_id = meta.tags.get_next_id();
|
||||
let id = id.unwrap_or_else(|| format!("leptos-link-{}", next_id.0));
|
||||
|
||||
let builder_el = leptos::leptos_dom::html::link(cx)
|
||||
.attr("id", &id)
|
||||
.attr("as", as_)
|
||||
.attr("crossorigin", crossorigin)
|
||||
.attr("disabled", disabled.unwrap_or(false))
|
||||
.attr("fetchpriority", fetchpriority)
|
||||
.attr("href", href)
|
||||
.attr("hreflang", hreflang)
|
||||
.attr("imagesizes", imagesizes)
|
||||
.attr("imagesrcset", imagesrcset)
|
||||
.attr("integrity", integrity)
|
||||
.attr("media", media)
|
||||
.attr("prefetch", prefetch)
|
||||
.attr("referrerpolicy", referrerpolicy)
|
||||
.attr("rel", rel)
|
||||
.attr("sizes", sizes)
|
||||
.attr("title", title)
|
||||
.attr("type", type_)
|
||||
.attr("blocking", blocking);
|
||||
let builder_el = leptos::leptos_dom::html::as_meta_tag({
|
||||
let id = id.clone();
|
||||
move || {
|
||||
leptos::leptos_dom::html::link(cx)
|
||||
.attr("id", &id)
|
||||
.attr("as", as_)
|
||||
.attr("crossorigin", crossorigin)
|
||||
.attr("disabled", disabled.unwrap_or(false))
|
||||
.attr("fetchpriority", fetchpriority)
|
||||
.attr("href", href)
|
||||
.attr("hreflang", hreflang)
|
||||
.attr("imagesizes", imagesizes)
|
||||
.attr("imagesrcset", imagesrcset)
|
||||
.attr("integrity", integrity)
|
||||
.attr("media", media)
|
||||
.attr("prefetch", prefetch)
|
||||
.attr("referrerpolicy", referrerpolicy)
|
||||
.attr("rel", rel)
|
||||
.attr("sizes", sizes)
|
||||
.attr("title", title)
|
||||
.attr("type", type_)
|
||||
.attr("blocking", blocking)
|
||||
}
|
||||
});
|
||||
|
||||
meta.tags.register(cx, id, builder_el.into_any());
|
||||
}
|
||||
|
||||
@@ -41,11 +41,13 @@ pub fn Meta(
|
||||
let next_id = meta.tags.get_next_id();
|
||||
let id = format!("leptos-link-{}", next_id.0);
|
||||
|
||||
let builder_el = leptos::leptos_dom::html::meta(cx)
|
||||
.attr("charset", move || charset.as_ref().map(|v| v.get()))
|
||||
.attr("name", move || name.as_ref().map(|v| v.get()))
|
||||
.attr("http-equiv", move || http_equiv.as_ref().map(|v| v.get()))
|
||||
.attr("content", move || content.as_ref().map(|v| v.get()));
|
||||
let builder_el = leptos::leptos_dom::html::as_meta_tag(move || {
|
||||
leptos::leptos_dom::html::meta(cx)
|
||||
.attr("charset", move || charset.as_ref().map(|v| v.get()))
|
||||
.attr("name", move || name.as_ref().map(|v| v.get()))
|
||||
.attr("http-equiv", move || http_equiv.as_ref().map(|v| v.get()))
|
||||
.attr("content", move || content.as_ref().map(|v| v.get()))
|
||||
});
|
||||
|
||||
meta.tags.register(cx, id, builder_el.into_any());
|
||||
}
|
||||
|
||||
@@ -67,19 +67,24 @@ pub fn Script(
|
||||
let next_id = meta.tags.get_next_id();
|
||||
let id = id.unwrap_or_else(|| format!("leptos-link-{}", next_id.0));
|
||||
|
||||
let builder_el = leptos::leptos_dom::html::script(cx)
|
||||
.attr("id", &id)
|
||||
.attr("async", async_)
|
||||
.attr("crossorigin", crossorigin)
|
||||
.attr("defer", defer)
|
||||
.attr("fetchpriority ", fetchpriority)
|
||||
.attr("integrity", integrity)
|
||||
.attr("nomodule", nomodule)
|
||||
.attr("nonce", nonce)
|
||||
.attr("referrerpolicy", referrerpolicy)
|
||||
.attr("src", src)
|
||||
.attr("type", type_)
|
||||
.attr("blocking", blocking);
|
||||
let builder_el = leptos::leptos_dom::html::as_meta_tag({
|
||||
let id = id.clone();
|
||||
move || {
|
||||
leptos::leptos_dom::html::script(cx)
|
||||
.attr("id", &id)
|
||||
.attr("async", async_)
|
||||
.attr("crossorigin", crossorigin)
|
||||
.attr("defer", defer)
|
||||
.attr("fetchpriority ", fetchpriority)
|
||||
.attr("integrity", integrity)
|
||||
.attr("nomodule", nomodule)
|
||||
.attr("nonce", nonce)
|
||||
.attr("referrerpolicy", referrerpolicy)
|
||||
.attr("src", src)
|
||||
.attr("type", type_)
|
||||
.attr("blocking", blocking)
|
||||
}
|
||||
});
|
||||
let builder_el = if let Some(children) = children {
|
||||
let frag = children(cx);
|
||||
let mut script = String::new();
|
||||
|
||||
@@ -46,12 +46,17 @@ pub fn Style(
|
||||
let next_id = meta.tags.get_next_id();
|
||||
let id = id.unwrap_or_else(|| format!("leptos-link-{}", next_id.0));
|
||||
|
||||
let builder_el = leptos::leptos_dom::html::style(cx)
|
||||
.attr("id", &id)
|
||||
.attr("media", media)
|
||||
.attr("nonce", nonce)
|
||||
.attr("title", title)
|
||||
.attr("blocking", blocking);
|
||||
let builder_el = leptos::leptos_dom::html::as_meta_tag({
|
||||
let id = id.clone();
|
||||
move || {
|
||||
leptos::leptos_dom::html::style(cx)
|
||||
.attr("id", &id)
|
||||
.attr("media", media)
|
||||
.attr("nonce", nonce)
|
||||
.attr("title", title)
|
||||
.attr("blocking", blocking)
|
||||
}
|
||||
});
|
||||
let builder_el = if let Some(children) = children {
|
||||
let frag = children(cx);
|
||||
let mut style = String::new();
|
||||
|
||||
Reference in New Issue
Block a user