Extend head components with global attributes (#2888)
* Fix hot reloading components with keys * include component formatted segment keys, but not dynamic component value * extend each head component with the corresponding element * Allow spreading custom attributes into components * Fix component_literal_dyn_idx index * add a new test for hot reloading components with keys * FIx script without body warning and rendering styles with a href set * fix clippy
This commit is contained in:
1 parent
c2b131f249
commit
95976d9a17
8 files changed
+863
-1134
No files matched your search
@@ -91,6 +91,7 @@ impl Document for ServerDocument {
|
||||
http_equiv: props.http_equiv,
|
||||
content: props.content,
|
||||
property: props.property,
|
||||
..props.additional_attributes
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -98,7 +99,7 @@ impl Document for ServerDocument {
|
||||
fn create_script(&self, props: ScriptProps) {
|
||||
self.warn_if_streaming();
|
||||
self.serialize_for_hydration();
|
||||
let children = props.script_contents();
|
||||
let children = props.script_contents().ok();
|
||||
self.0.borrow_mut().script.push(rsx! {
|
||||
script {
|
||||
src: props.src,
|
||||
@@ -110,11 +111,46 @@ impl Document for ServerDocument {
|
||||
nonce: props.nonce,
|
||||
referrerpolicy: props.referrerpolicy,
|
||||
r#type: props.r#type,
|
||||
..props.additional_attributes,
|
||||
{children}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn create_style(&self, props: StyleProps) {
|
||||
self.warn_if_streaming();
|
||||
self.serialize_for_hydration();
|
||||
match (&props.href, props.style_contents()) {
|
||||
// The style has inline contents, render it as a style tag
|
||||
(_, Ok(contents)) => self.0.borrow_mut().script.push(rsx! {
|
||||
style {
|
||||
media: props.media,
|
||||
nonce: props.nonce,
|
||||
title: props.title,
|
||||
..props.additional_attributes,
|
||||
{contents}
|
||||
}
|
||||
}),
|
||||
// The style has a href, render it as a link tag
|
||||
(Some(_), _) => {
|
||||
self.0.borrow_mut().script.push(rsx! {
|
||||
link {
|
||||
rel: "stylesheet",
|
||||
href: props.href,
|
||||
media: props.media,
|
||||
nonce: props.nonce,
|
||||
title: props.title,
|
||||
..props.additional_attributes,
|
||||
}
|
||||
});
|
||||
}
|
||||
// The style has neither contents nor src, log an error
|
||||
(None, Err(err)) => {
|
||||
err.log("Style");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_link(&self, props: head::LinkProps) {
|
||||
self.warn_if_streaming();
|
||||
self.serialize_for_hydration();
|
||||
|
||||
Reference in new issue
Block a user