fix(board status): resolve offline indicators with strict community refs

This commit is contained in:
Tommaso Casaburi
2026-04-17 12:51:14 +07:00
parent 1c2be5a172
commit 4cae9c3caa
7 changed files with 86 additions and 64 deletions
@@ -10,6 +10,8 @@ const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise
const testState = vi.hoisted(() => ({
accountComment: undefined as { communityAddress?: string } | undefined,
community: { address: 'music-posting.eth' } as { address?: string; name?: string; publicKey?: string } | undefined,
communityIdentifier: { name: 'music-posting.eth' } as { name?: string; publicKey?: string } | undefined,
directories: [{ address: 'music-posting.eth', title: '/mu/ - Music' }] as Array<{ address: string; title?: string }>,
directoriesMetadata: { title: '/all/ - Directories' } as { title?: string } | undefined,
isMobile: false,
@@ -52,6 +54,7 @@ vi.mock('react-router-dom', async () => {
vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
useAccount: () => undefined,
useAccountComment: () => testState.accountComment,
useCommunity: () => testState.community,
}));
vi.mock('@bitsocialnet/bitsocial-react-hooks/dist/stores/accounts', () => ({
@@ -82,6 +85,10 @@ vi.mock('../../../hooks/use-directories', () => ({
useDirectoriesMetadata: () => testState.directoriesMetadata,
}));
vi.mock('../../../hooks/use-community-identifiers', () => ({
useCommunityIdentifier: () => testState.communityIdentifier,
}));
vi.mock('../../../hooks/use-resolved-community-address', () => ({
useResolvedCommunityAddress: () => testState.resolvedAddress,
}));
@@ -122,6 +129,8 @@ describe('BoardHeader', () => {
beforeEach(() => {
vi.clearAllMocks();
testState.accountComment = undefined;
testState.community = { address: 'music-posting.eth' };
testState.communityIdentifier = { name: 'music-posting.eth' };
testState.directories = [{ address: 'music-posting.eth', title: '/mu/ - Music' }];
testState.directoriesMetadata = { title: '/all/ - Directories' };
testState.isMobile = false;
+5 -4
View File
@@ -1,9 +1,10 @@
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useParams, useNavigate } from 'react-router-dom';
import { useCommunity } from '@bitsocialnet/bitsocial-react-hooks';
import useAccountsStore from '@bitsocialnet/bitsocial-react-hooks/dist/stores/accounts';
import useCommunitiesStore from '@bitsocialnet/bitsocial-react-hooks/dist/stores/communities';
import getShortAddress from '../../lib/get-short-address';
import { useCommunityIdentifier } from '../../hooks/use-community-identifiers';
import { useStableCommunity } from '../../hooks/use-stable-community';
import { isAllView, isSubscriptionsView, isModView } from '../../lib/utils/view-utils';
import { isArchiveRoute } from '../../lib/utils/route-utils';
@@ -27,9 +28,9 @@ const ImageBanner = () => {
// Separate component for offline indicator to isolate rerenders from updatingState
// Only this component will rerender when updatingState changes, not the whole BoardHeader
const OfflineIndicator = ({ communityAddress }: { communityAddress: string | undefined }) => {
// Subscribe to full community including transient state for offline detection
const community = useCommunitiesStore((state) => (communityAddress ? state.communities[communityAddress] : undefined));
const { isOffline, isOnlineStatusLoading, offlineIconClass, offlineTitle } = useIsCommunityOffline(community);
const communityIdentifier = useCommunityIdentifier(communityAddress);
const community = useCommunity(communityIdentifier ? { community: communityIdentifier } : undefined);
const { isOffline, isOnlineStatusLoading, offlineIconClass, offlineTitle } = useIsCommunityOffline(community, communityAddress);
if (!isOffline && !isOnlineStatusLoading) {
return null;