Skip to content

Commit 7b3e62f

Browse files
committed
fix: fixed error page duplication without hydration
Also fixed a longstanding bug in which errors created from faulty links within the app appear in addition to the current page.
1 parent b71fa41 commit 7b3e62f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

examples/basic/.perseus/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,21 @@ pub fn run() -> Result<(), JsValue> {
116116
if let InitialState::Error(ErrorPageData { url, status, err }) = get_initial_state() {
117117
let initial_container = initial_container.unwrap();
118118
// We need to move the server-rendered content from its current container to the reactive container (otherwise Sycamore can't work with it properly)
119-
let initial_html = initial_container.inner_html();
120-
container_rx_elem.set_inner_html(&initial_html);
119+
// If we're not hydrating, there's no point in moving anything over, we'll just fully re-render
120+
#[cfg(feature = "hydrate")]
121+
{
122+
let initial_html = initial_container.inner_html();
123+
container_rx_elem.set_inner_html(&initial_html);
124+
}
121125
initial_container.set_inner_html("");
122126
// Make the initial container invisible
123127
initial_container.set_attribute("style", "display: none;").unwrap();
124128
// Hydrate the error pages
125129
// Right now, we don't provide translators to any error pages that have come from the server
126130
error_pages.render_page(&url, &status, &err, None, &container_rx_elem);
127131
} else {
132+
// This is an error from navigating within the app (probably the dev mistyped a link...), so we'll clear the page
133+
container_rx_elem.set_inner_html("");
128134
error_pages.render_page("", &404, "not found", None, &container_rx_elem);
129135
}
130136
},

packages/perseus/src/shell.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,12 @@ pub async fn app_shell(
414414
InitialState::Error(ErrorPageData { url, status, err }) => {
415415
checkpoint("initial_state_error");
416416
// We need to move the server-rendered content from its current container to the reactive container (otherwise Sycamore can't work with it properly)
417-
let initial_html = initial_container.inner_html();
418-
container_rx_elem.set_inner_html(&initial_html);
417+
// If we're not hydrating, there's no point in moving anything over, we'll just fully re-render
418+
#[cfg(feature = "hydrate")]
419+
{
420+
let initial_html = initial_container.inner_html();
421+
container_rx_elem.set_inner_html(&initial_html);
422+
}
419423
initial_container.set_inner_html("");
420424
// Make the initial container invisible
421425
initial_container
@@ -424,6 +428,8 @@ pub async fn app_shell(
424428
// Hydrate the currently static error page
425429
// Right now, we don't provide translators to any error pages that have come from the server
426430
// We render this rather than hydrating because otherwise we'd need a `HydrateNode` at the plugins level, which is way too inefficient
431+
#[cfg(not(feature = "hydrate"))]
432+
container_rx_elem.set_inner_html("");
427433
error_pages.render_page(&url, &status, &err, None, &container_rx_elem);
428434
}
429435
};

0 commit comments

Comments
 (0)