Skip to content

Commit

Permalink
"Fix" the hydration issue
Browse files Browse the repository at this point in the history
- At the core of the matter it is a situation where a node got rendered
  before the suspended bit actually got to update something that node
  depended on and thus invalidating the expectations within hydration.
- The fix is to not have a general ContentAction but rather have it be
  part of the output per component.  Not a terrible tradeoff, aside from
  some added code duplication per component.  The interesting part is
  that the outlet is also part of the suspense.
  • Loading branch information
metatoaster committed Nov 1, 2024
1 parent 7338cb3 commit e21de74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
2 changes: 0 additions & 2 deletions pmrapp/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use leptos_router::{
};

use crate::ac::{
ContentAction,
ACRoutes,
SessionStatus,
provide_session_context,
Expand Down Expand Up @@ -80,7 +79,6 @@ pub fn App() -> impl IntoView {
</header>
<main>
<article>
<ContentAction/>
<Routes fallback=|| {
let mut errors = Errors::default();
errors.insert_with_default_key(AppError::NotFound);
Expand Down
22 changes: 9 additions & 13 deletions pmrapp/src/exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use std::str::FromStr;

pub mod api;

use crate::ac::AccountCtx;
use crate::ac::{
AccountCtx,
ContentAction,
};
use crate::error::AppError;
use crate::error_template::ErrorTemplate;
use crate::component::{Redirect, RedirectTS};
Expand Down Expand Up @@ -149,17 +152,7 @@ pub fn Exposure() -> impl IntoView {
let resource = exposure_info.as_ref().ok().map(|info| {
format!("/exposure/{}/", info.exposure.id)
});
// set_resource.set(resource.clone());

// FIXME using effect to workaround some hydration conflict for now. As this value
// is set _after_ some key moment (possibly when the node was already rendered with
// nothing), setting this immediately will result in the hydration value having the
// resource defined, resulting in the mismatch of SSR rendering of <ContentAction/>
// as it was already done without resource defined.
//
// This issue may also be resolved by moving the <ContentAction/> after the router,
// but this would also move the element which isn't ideal. Can resolve this later.
Effect::new(move |_| set_resource.set(resource.clone()));
set_resource.set(resource.clone());

expect_context::<WriteSignal<Option<ExposureSourceCtx>>>()
.set(exposure_info.as_ref().map(|info| {
Expand Down Expand Up @@ -187,6 +180,10 @@ pub fn Exposure() -> impl IntoView {
})
.collect::<Vec<_>>()))
}).ok());
view! {
<ContentAction/>
<Outlet/>
}
})
};

Expand All @@ -195,7 +192,6 @@ pub fn Exposure() -> impl IntoView {
<Suspense>
{portlets}
</Suspense>
<Outlet/>
}
}

Expand Down

0 comments on commit e21de74

Please sign in to comment.