Skip to content

Commit 17cf62c

Browse files
committed
ssr mode works properly now
1 parent ec7d916 commit 17cf62c

10 files changed

Lines changed: 626 additions & 460 deletions

File tree

crates/weaver-app/src/blobcache.rs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,28 @@ impl BlobCache {
4242
}
4343
AtIdentifier::Handle(handle) => self.client.pds_for_handle(&handle).await?,
4444
};
45-
// let blob = if let Ok(blob_stream) = self
46-
// .client
47-
// .xrpc(pds_url)
48-
// .send(
49-
// &GetBlob::new()
50-
// .cid(cid.clone())
51-
// .did(repo_did.clone())
52-
// .build(),
53-
// )
54-
// .await
55-
// {
56-
// blob_stream.buffer().clone()
57-
// } else {
58-
// reqwest::get(format!(
59-
// "https://cdn.bsky.app/img/feed_fullsize/plain/{}/{}@jpeg",
60-
// repo_did, cid
61-
// ))
62-
// .await?
63-
// .bytes()
64-
// .await?
65-
// .clone()
66-
// };
67-
//
68-
let blob = reqwest::get(format!(
69-
"https://cdn.bsky.app/img/feed_fullsize/plain/{}/{}@jpeg",
70-
repo_did, cid
71-
))
72-
.await?
73-
.bytes()
74-
.await?
75-
.clone();
45+
let blob = if let Ok(blob_stream) = self
46+
.client
47+
.xrpc(pds_url)
48+
.send(
49+
&GetBlob::new()
50+
.cid(cid.clone())
51+
.did(repo_did.clone())
52+
.build(),
53+
)
54+
.await
55+
{
56+
blob_stream.buffer().clone()
57+
} else {
58+
reqwest::get(format!(
59+
"https://cdn.bsky.app/img/feed_fullsize/plain/{}/{}@jpeg",
60+
repo_did, cid
61+
))
62+
.await?
63+
.bytes()
64+
.await?
65+
.clone()
66+
};
7667

7768
self.cache.insert(cid.clone(), blob);
7869
if let Some(name) = name {

crates/weaver-app/src/components/entry.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,46 @@ use jacquard::{
2424
use std::sync::Arc;
2525
use weaver_api::sh_weaver::notebook::{BookEntryView, EntryView, entry};
2626

27-
#[component]
28-
pub fn EntryPage(
29-
ident: ReadSignal<AtIdentifier<'static>>,
30-
book_title: ReadSignal<SmolStr>,
31-
title: ReadSignal<SmolStr>,
32-
) -> Element {
33-
tracing::debug!(
34-
"EntryPage component rendering for ident: {:?}, book: {}, title: {}",
35-
ident(),
36-
book_title(),
37-
title()
38-
);
39-
rsx! {
40-
{std::iter::once(rsx! {Entry {ident, book_title, title}})}
41-
}
42-
}
27+
// #[component]
28+
// pub fn EntryPage(
29+
// ident: ReadSignal<AtIdentifier<'static>>,
30+
// book_title: ReadSignal<SmolStr>,
31+
// title: ReadSignal<SmolStr>,
32+
// ) -> Element {
33+
// rsx! {
34+
// {std::iter::once(rsx! {Entry {ident, book_title, title}})}
35+
// }
36+
// }
4337

4438
#[component]
45-
pub fn Entry(
39+
pub fn EntryPage(
4640
ident: ReadSignal<AtIdentifier<'static>>,
4741
book_title: ReadSignal<SmolStr>,
4842
title: ReadSignal<SmolStr>,
4943
) -> Element {
50-
tracing::debug!(
51-
"Entry component rendering for ident: {:?}, book: {}, title: {}",
52-
ident(),
53-
book_title(),
54-
title()
55-
);
5644
// Use feature-gated hook for SSR support
57-
let entry = crate::data::use_entry_data(ident, book_title, title);
45+
let (entry_res, entry) = crate::data::use_entry_data(ident, book_title, title);
46+
let route = use_route::<Route>();
47+
let mut last_route = use_signal(|| route.clone());
48+
49+
#[cfg(all(
50+
target_family = "wasm",
51+
target_os = "unknown",
52+
not(feature = "fullstack-server")
53+
))]
5854
let fetcher = use_context::<crate::fetch::Fetcher>();
59-
tracing::debug!("Entry component got entry data");
55+
56+
// Suspend SSR until entry loads
57+
#[cfg(feature = "fullstack-server")]
58+
let mut entry_res = entry_res?;
59+
60+
#[cfg(feature = "fullstack-server")]
61+
use_effect(use_reactive!(|route| {
62+
if route != last_route() {
63+
entry_res.restart();
64+
last_route.set(route.clone());
65+
}
66+
}));
6067

6168
// Handle blob caching when entry data is available
6269
match &*entry.read() {

crates/weaver-app/src/components/identity.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ pub fn RepositoryIndex(ident: ReadSignal<AtIdentifier<'static>>) -> Element {
2626
ident()
2727
);
2828
use crate::components::ProfileDisplay;
29-
let notebooks = data::use_notebooks_for_did(ident);
30-
let profile = crate::data::use_profile_data(ident);
29+
let (notebooks_result, notebooks) = data::use_notebooks_for_did(ident);
30+
let (profile_result, profile) = crate::data::use_profile_data(ident);
3131
tracing::debug!("RepositoryIndex got profile and notebooks");
32+
33+
#[cfg(feature = "fullstack-server")]
34+
notebooks_result?;
35+
36+
#[cfg(feature = "fullstack-server")]
37+
profile_result?;
38+
3239
rsx! {
3340
document::Stylesheet { href: NOTEBOOK_CARD_CSS }
3441

crates/weaver-app/src/components/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use css::NotebookCss;
77

88
mod entry;
99
#[allow(unused_imports)]
10-
pub use entry::{Entry, EntryCard, EntryMarkdown, EntryPage};
10+
pub use entry::{EntryCard, EntryMarkdown, EntryPage};
1111

1212
pub mod identity;
1313
#[allow(unused_imports)]

0 commit comments

Comments
 (0)