Fix empty board loading state and browser P2P patch (#1175)

* fix(board): show loaded empty boards

* fix(p2p): patch browser hooks runtime

* fix(board): stop flash loading for explicit empty boards

* fix(board): wait for feed on preloaded empty pages
This commit is contained in:
Tommaso Casaburi
2026-06-18 18:54:48 +07:00
committed by GitHub
parent 9896c4400b
commit eb47214f08
9 changed files with 821 additions and 240 deletions
@@ -61,6 +61,46 @@ describe('getRawBoardThreadState', () => {
).toBe(true);
});
it('treats explicit empty page CIDs as a fully loaded empty board', () => {
const community = {
posts: {
pageCids: {},
pages: {},
},
updatedAt: 1781773422,
} as Community;
expect(
getRawBoardThreadState({
accountId: undefined,
communitiesPages: {} as CommunitiesPages,
community,
sortType: 'active',
}),
).toMatchObject({
isFullyLoaded: true,
rootThreadCids: new Set<string>(),
});
});
it('does not treat placeholder empty page CIDs as fully loaded', () => {
const community = {
posts: {
pageCids: {},
pages: {},
},
} as Community;
expect(
getRawBoardThreadState({
accountId: undefined,
communitiesPages: {} as CommunitiesPages,
community,
sortType: 'active',
}).isFullyLoaded,
).toBe(false);
});
it('walks stored board pages without importing side-effectful stores', () => {
const community = {
posts: {
+7 -1
View File
@@ -1,11 +1,13 @@
import type { Comment, CommunitiesPages, Community, CommunityPage } from '@bitsocial/bitsocial-react-hooks';
export type RawBoardThreadState = {
hasExplicitEmptyPageCids: boolean;
isFullyLoaded: boolean;
rootThreadCids: Set<string>;
};
const EMPTY_RAW_BOARD_THREAD_STATE: RawBoardThreadState = {
hasExplicitEmptyPageCids: false,
isFullyLoaded: false,
rootThreadCids: new Set<string>(),
};
@@ -80,6 +82,7 @@ export const getRawBoardThreadState = ({
if (pages.length > 0) {
return {
hasExplicitEmptyPageCids: false,
isFullyLoaded: !pages[pages.length - 1]?.nextCid,
rootThreadCids,
};
@@ -88,6 +91,8 @@ export const getRawBoardThreadState = ({
const hasPageCid = Boolean(community.posts?.pageCids?.[sortType]);
const preloadedPages = (preloadedSortPage ? [preloadedSortPage] : []) as Array<{ comments?: Comment[]; nextCid?: string }>;
const hasCompletePreloadedPage = !hasPageCid && preloadedPages.some((page) => Array.isArray(page?.comments)) && preloadedPages.every((page) => !page?.nextCid);
const hasFetchedCommunityUpdate = typeof community.updatedAt === 'number' || typeof community.updateCid === 'string';
const hasExplicitEmptyPageCids = hasFetchedCommunityUpdate && Boolean(community.posts?.pageCids && !hasPageCid);
if (hasCompletePreloadedPage) {
for (const page of preloadedPages) {
@@ -96,7 +101,8 @@ export const getRawBoardThreadState = ({
}
return {
isFullyLoaded: hasCompletePreloadedPage,
hasExplicitEmptyPageCids,
isFullyLoaded: hasCompletePreloadedPage || hasExplicitEmptyPageCids,
rootThreadCids,
};
};