From 382d5cb8c5fdac65125cfd059635964957d1e100 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 30 May 2023 10:32:17 -0500 Subject: [PATCH] fix hot reloading with namespaces --- packages/core/src/nodes.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index da139e78a..dabb479cb 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -284,6 +284,17 @@ where Ok(&*Box::leak(deserialized)) } +#[cfg(feature = "serialize")] +fn deserialize_option_leaky<'a, 'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + use serde::Deserialize; + + let deserialized = Option::::deserialize(deserializer)?; + Ok(deserialized.map(|deserialized| &*Box::leak(deserialized.into_boxed_str()))) +} + impl<'a> Template<'a> { /// Is this template worth caching at all, since it's completely runtime? /// @@ -319,6 +330,10 @@ pub enum TemplateNode<'a> { /// /// In HTML, this would be a valid URI that defines a namespace for all elements below it /// SVG is an example of this namespace + #[cfg_attr( + feature = "serialize", + serde(deserialize_with = "deserialize_option_leaky") + )] namespace: Option<&'a str>, /// A list of possibly dynamic attribues for this element