Skip to content

Commit 6f2843f

Browse files
committed
fix: prevent permanent loading screen when navigating between pages
Two bugs in page content loading caused pages to show "Loading..." forever: 1. When readPageContent returned null (file doesn't exist on disk yet), pageContents[id] was never set, so contentLoaded stayed false forever. Fix: fall back to empty string when backend returns null. 2. The check `!pageContents[id]` treated empty string '' as falsy, causing re-reads from backend on every navigation to pages with empty content. Fix: use `!(id in pageContents)` for proper existence check. Applied the fix in all three code paths: handlePageSelect, initial load, and loadAndApplySpaceState (space switching). https://claude.ai/code/session_01WsFd9hPNmHcP9kJCj7fZHM
1 parent 57c033b commit 6f2843f

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

packages/ui/src/components/App.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ export function App() {
168168
// Load selected page content
169169
if (state.selectedPageId) {
170170
const content = await readSpacePageContent(backend, spaceId, state.selectedPageId);
171-
if (content !== null) {
172-
setPageContents((prev) => ({ ...prev, [state.selectedPageId!]: content }));
173-
}
171+
// Set content even when null (file doesn't exist yet) — use empty string
172+
// to avoid getting stuck in a permanent loading state
173+
setPageContents((prev) => ({ ...prev, [state.selectedPageId!]: content ?? '' }));
174174
}
175175
} else {
176176
// Empty space
@@ -212,9 +212,9 @@ export function App() {
212212
// Load selected page content from backend
213213
if (persisted.selectedPageId) {
214214
void readPageContent(backend, persisted.selectedPageId).then((content) => {
215-
if (content !== null) {
216-
setPageContents((prev) => ({ ...prev, [persisted.selectedPageId!]: content }));
217-
}
215+
// Set content even when null (file doesn't exist yet) — use empty string
216+
// to avoid getting stuck in a permanent loading state
217+
setPageContents((prev) => ({ ...prev, [persisted.selectedPageId!]: content ?? '' }));
218218
});
219219
}
220220
} else if (shouldShowDemo) {
@@ -358,11 +358,12 @@ export function App() {
358358
addToRecent(id, node.title, node.icon);
359359
}
360360
// Load page content from backend if not already cached
361-
if (!pageContents[id]) {
361+
// Use `in` check instead of falsy check — empty string '' is valid content
362+
if (!(id in pageContents)) {
362363
void currentReadPage(id).then((content) => {
363-
if (content !== null) {
364-
setPageContents((prev) => ({ ...prev, [id]: content }));
365-
}
364+
// Set content even when null (page file doesn't exist yet) — use empty string
365+
// to avoid getting stuck in a permanent loading state
366+
setPageContents((prev) => ({ ...prev, [id]: content ?? '' }));
366367
});
367368
}
368369
// Close sidebar on narrow screens after selecting a page

0 commit comments

Comments
 (0)