mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
fix: set <Title/>
text and formatter in context during client-side rendering (closes #2715)
This commit is contained in:
parent
89bbdc58af
commit
25bfc27544
1 changed files with 17 additions and 17 deletions
|
@ -181,20 +181,22 @@ impl TitleView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)] // TODO these should be used to rebuild the attributes, I guess
|
|
||||||
struct TitleViewState {
|
struct TitleViewState {
|
||||||
el: HtmlTitleElement,
|
|
||||||
formatter: Option<Formatter>,
|
|
||||||
text: Option<TextProp>,
|
|
||||||
effect: RenderEffect<Oco<'static, str>>,
|
effect: RenderEffect<Oco<'static, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render<Dom> for TitleView {
|
impl Render<Dom> for TitleView {
|
||||||
type State = TitleViewState;
|
type State = TitleViewState;
|
||||||
|
|
||||||
fn build(self) -> Self::State {
|
fn build(mut self) -> Self::State {
|
||||||
let el = self.el();
|
let el = self.el();
|
||||||
let meta = self.meta;
|
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 effect = RenderEffect::new({
|
||||||
let el = el.clone();
|
let el = el.clone();
|
||||||
move |prev| {
|
move |prev| {
|
||||||
|
@ -207,16 +209,11 @@ impl Render<Dom> for TitleView {
|
||||||
text
|
text
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
TitleViewState {
|
TitleViewState { effect }
|
||||||
el,
|
|
||||||
formatter: self.formatter,
|
|
||||||
text: self.text,
|
|
||||||
effect,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rebuild(self, _state: &mut Self::State) {
|
fn rebuild(self, state: &mut Self::State) {
|
||||||
// TODO should this rebuild?
|
*state = self.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,12 +254,18 @@ impl RenderHtml<Dom> for TitleView {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hydrate<const FROM_SERVER: bool>(
|
fn hydrate<const FROM_SERVER: bool>(
|
||||||
self,
|
mut self,
|
||||||
_cursor: &Cursor<Dom>,
|
_cursor: &Cursor<Dom>,
|
||||||
_position: &PositionState,
|
_position: &PositionState,
|
||||||
) -> Self::State {
|
) -> Self::State {
|
||||||
let el = self.el();
|
let el = self.el();
|
||||||
let meta = self.meta;
|
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 effect = RenderEffect::new({
|
||||||
let el = el.clone();
|
let el = el.clone();
|
||||||
move |prev| {
|
move |prev| {
|
||||||
|
@ -277,9 +280,6 @@ impl RenderHtml<Dom> for TitleView {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
TitleViewState {
|
TitleViewState {
|
||||||
el,
|
|
||||||
formatter: self.formatter,
|
|
||||||
text: self.text,
|
|
||||||
effect,
|
effect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue