fix: never resolve LocalResource synchronously (closes #2736)

This commit is contained in:
Greg Johnston 2024-07-28 16:31:19 -04:00
parent 5fb80aaa40
commit f2d6375d93
2 changed files with 13 additions and 0 deletions

View File

@ -18,6 +18,7 @@ server_fn = { workspace = true }
tracing = { version = "0.1", optional = true }
futures = "0.3"
any_spawner = { workspace = true }
tachys = { workspace = true, optional = true, features = ["reactive_graph"] }
# serialization formats

View File

@ -48,6 +48,12 @@ impl<T> ArcLocalResource<T> {
if cfg!(feature = "ssr") {
pending().await
} else {
// LocalResources that are immediately available can cause a hydration error,
// because the future *looks* like it is alredy ready (and therefore would
// already have been rendered to html on the server), but in fact was ignored
// on the server. the simplest way to avoid this is to ensure that we always
// wait a tick before resolving any value for a localresource.
any_spawner::Executor::tick().await;
fut.await
}
}
@ -198,6 +204,12 @@ impl<T> LocalResource<T> {
if cfg!(feature = "ssr") {
pending().await
} else {
// LocalResources that are immediately available can cause a hydration error,
// because the future *looks* like it is alredy ready (and therefore would
// already have been rendered to html on the server), but in fact was ignored
// on the server. the simplest way to avoid this is to ensure that we always
// wait a tick before resolving any value for a localresource.
any_spawner::Executor::tick().await;
fut.await
}
}