Skip to content

Commit 53058ba

Browse files
committed
fix(routing): 🐛 fixed error duplication on initial load
1 parent 197956b commit 53058ba

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

examples/cli/.perseus/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ pub fn run() -> Result<(), JsValue> {
7777
// Those all go to the same system that redirects to the appropriate locale
7878
// Note that `container` doesn't exist for this scenario
7979
RouteVerdict::LocaleDetection(path) => detect_locale(path.clone(), get_locales()),
80-
// We handle the 404 for the user for convenience
8180
// To get a translator here, we'd have to go async and dangerously check the URL
8281
// If this is an initial load, there'll already be an error message, so we should only proceed if the declaration is not `error`
8382
RouteVerdict::NotFound => {
8483
if let InitialState::Error(ErrorPageData { url, status, err }) = get_initial_state() {
84+
let initial_container = initial_container.unwrap();
85+
// We need to move the server-rendered content from its current container to the reactive container (otherwise Sycamore can't work with it properly)
86+
let initial_html = initial_container.inner_html();
87+
container_rx_elem.set_inner_html(&initial_html);
88+
initial_container.set_inner_html("");
8589
// Hydrate the error pages
8690
// Right now, we don't provide translators to any error pages that have come from the server
8791
error_pages.hydrate_page(&url, &status, &err, None, &container_rx_elem);

packages/perseus-actix-web/src/initial_load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub async fn initial_load<C: ConfigManager, T: TranslationsManager>(
106106
};
107107
// Create a translator here, we'll use it twice
108108
let translator_raw = translations_manager
109-
.get_translator_for_locale(locale.to_string())
109+
.get_translator_for_locale("locale".to_string())
110110
.await;
111111
let translator_raw = match translator_raw {
112112
Ok(translator_raw) => translator_raw,

packages/perseus/src/shell.rs

+4
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ pub async fn app_shell(
293293
}
294294
// Nothing should be done if an error was sent down
295295
InitialState::Error(ErrorPageData { url, status, err }) => {
296+
// We need to move the server-rendered content from its current container to the reactive container (otherwise Sycamore can't work with it properly)
297+
let initial_html = initial_container.inner_html();
298+
container_rx_elem.set_inner_html(&initial_html);
299+
initial_container.set_inner_html("");
296300
// Hydrate the currently static error page
297301
// Right now, we don't provide translators to any error pages that have come from the server
298302
error_pages.hydrate_page(&url, &status, &err, None, &container_rx_elem);

0 commit comments

Comments
 (0)