-
-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use_resource.suspend()
not working with SSR
#3643
Comments
I am working on hydration documentation in DioxusLabs/docsite#397 which will include hydration errors like this |
@ealmloff Thank you. The
BTW, is this the correct way of using the #[component]
fn App() -> Element {
let session = use_server_future(move || async move {
let session = Session {
username: "Freddie Mercury".to_string(),
};
session
})?;
session.as_ref().map(|session| {
*SESSION.write() = Some(session.clone());
});
rsx! {
p { "Session: {session:?}" }
p { "Global Session: {SESSION:?}" }
}
} |
I do get that error if you just add the
Close, that code will write to SESSION every time the component runs which can cause a bunch of unnecessary reruns. You can move it into #![allow(non_snake_case)]
use dioxus::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Session {
pub username: String,
}
pub static SESSION: GlobalSignal<Option<Session>> = Global::new(|| None);
fn main() {
launch(app);
}
#[component]
fn app() -> Element {
let session = use_server_future(move || async move {
let session = Session {
username: "Freddie Mercury".to_string(),
};
session
})?;
use_memo(move || {
*SESSION.write() = session();
});
rsx! {
p { "Session: {session:?}" }
p { "Global Session: {SESSION:?}" }
}
} |
Problem
The documentation of the
suspend
function states:but this is not true when rendering is performed on the server.
Steps To Reproduce
This code reproduces the issue:
main.rs
Cargo.toml
When the page is loaded, the server returns:
then soon after, when the client is hydrated, the page turns to:
Expected behavior
I would expect the server to have the same rendering behavior as the client, and to directly return:
I also tried other hook types, like
use_server_future
, but I could not find a clean way to have the same behavior on the server and web client which is a requirement I have for SEO.Environment:
web
The text was updated successfully, but these errors were encountered: