From 25bfc275448bb191edbe6204d5d5e68d8397a88c Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Thu, 25 Jul 2024 11:39:08 -0400 Subject: [PATCH] fix: set `` text and formatter in context during client-side rendering (closes #2715) --- meta/src/title.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/meta/src/title.rs b/meta/src/title.rs index 8b4f8c783..5adb9fa82 100644 --- a/meta/src/title.rs +++ b/meta/src/title.rs @@ -181,20 +181,22 @@ impl TitleView { } } -#[allow(dead_code)] // TODO these should be used to rebuild the attributes, I guess struct TitleViewState { - el: HtmlTitleElement, - formatter: Option<Formatter>, - text: Option<TextProp>, effect: RenderEffect<Oco<'static, str>>, } impl Render<Dom> for TitleView { type State = TitleViewState; - fn build(self) -> Self::State { + fn build(mut self) -> Self::State { let el = self.el(); let meta = self.meta; + if let Some(formatter) = self.formatter.take() { + *meta.title.formatter.write().or_poisoned() = Some(formatter); + } + if let Some(text) = self.text.take() { + *meta.title.text.write().or_poisoned() = Some(text); + } let effect = RenderEffect::new({ let el = el.clone(); move |prev| { @@ -207,16 +209,11 @@ impl Render<Dom> for TitleView { text } }); - TitleViewState { - el, - formatter: self.formatter, - text: self.text, - effect, - } + TitleViewState { effect } } - fn rebuild(self, _state: &mut Self::State) { - // TODO should this rebuild? + fn rebuild(self, state: &mut Self::State) { + *state = self.build(); } } @@ -257,12 +254,18 @@ impl RenderHtml<Dom> for TitleView { } fn hydrate<const FROM_SERVER: bool>( - self, + mut self, _cursor: &Cursor<Dom>, _position: &PositionState, ) -> Self::State { let el = self.el(); let meta = self.meta; + if let Some(formatter) = self.formatter.take() { + *meta.title.formatter.write().or_poisoned() = Some(formatter); + } + if let Some(text) = self.text.take() { + *meta.title.text.write().or_poisoned() = Some(text); + } let effect = RenderEffect::new({ let el = el.clone(); move |prev| { @@ -277,9 +280,6 @@ impl RenderHtml<Dom> for TitleView { } }); TitleViewState { - el, - formatter: self.formatter, - text: self.text, effect, } }