Skip to content

Commit 6d38da6

Browse files
committed
fix: fixed cause of perseus hydration bugs
1 parent 77a9ffc commit 6d38da6

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

packages/perseus/src/client.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,9 @@ pub fn run_client<M: MutableStore, T: TranslationsManager>(
111111
}
112112
};
113113

114-
// If we're using hydration, everything has to be done inside a hydration
115-
// context (because of all the custom view handling)
116-
#[cfg(feature = "hydrate")]
117-
{
118-
running = with_hydration_context(|| core());
119-
}
120-
#[cfg(not(feature = "hydrate"))]
121-
{
122-
running = core();
123-
}
114+
// NOTE: To anyone who ever thinks it might be a good idea to put this whole
115+
// thing in a `with_hydration_cx()`, it's not, it's really not.
116+
core();
124117
});
125118

126119
dispatch_loaded(running, false);

packages/perseus/src/reactor/start.rs

-3
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,6 @@ impl Reactor<BrowserNodeType> {
416416
// This template is reactive, and will be updated as necessary
417417
view! { cx,
418418
(*self.current_view.get())
419-
// BUG: Without this, any page that renders only one top-level node will lead to a hydration
420-
// error. Pending input from Sycamore...
421-
div {}
422419
}
423420
}
424421
)

packages/perseus/src/utils/render.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use sycamore::{prelude::Scope, view::View};
1414
///
1515
/// **Warning:** if hydration is being used, it is expected that
1616
/// the given view was created inside a `with_hydration_context()` closure.
17-
// TODO Make sure hydration will work when it's targeted at a blank canvas...
1817
// XXX This is *highly* dependent on internal Sycamore implementation
1918
// details! (TODO PR for `hydrate_to_with_scope` etc.)
2019
#[cfg(any(client, doc))]
@@ -25,6 +24,8 @@ pub(crate) fn render_or_hydrate(
2524
parent: web_sys::Element,
2625
force_render: bool,
2726
) {
27+
use sycamore::utils::hydrate::{with_hydration_context, with_no_hydration_context};
28+
2829
#[cfg(feature = "hydrate")]
2930
{
3031
use sycamore::web::HydrateNode;
@@ -50,7 +51,11 @@ pub(crate) fn render_or_hydrate(
5051
insert(
5152
cx,
5253
&HydrateNode::from_web_sys(parent.into()),
53-
view, // We assume this was created in `with_hydration_context(..)`
54+
if force_render {
55+
with_no_hydration_context(|| view)
56+
} else {
57+
with_hydration_context(|| view)
58+
},
5459
if force_render {
5560
None
5661
} else {

0 commit comments

Comments
 (0)