fix(sidebar): scope hierarchy virtualizer keys by parent (#1561)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

Fixes #1495

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
Shea authored and GitHub committed 2026-08-07 08:02:35 +00:00
commit 80ecea37d5
4 files changed
+29 -4

No files matched your search

+2 -2
View File
@@ -17,7 +17,7 @@ import { produce } from 'immer';
import { useSpace } from '$hooks/useSpace';
import { Page, PageContent, PageContentCenter, PageHeroSection } from '$components/page';
import type { HierarchyItem, HierarchyItemSpace } from '$hooks/useSpaceHierarchy';
import { useSpaceHierarchy } from '$hooks/useSpaceHierarchy';
import { getSpaceHierarchyItemKey, useSpaceHierarchy } from '$hooks/useSpaceHierarchy';
import { VirtualTile } from '$components/virtualizer';
import { spaceRoomsAtom } from '$state/spaceRooms';
import { useSetting } from '$state/hooks/settings';
@@ -301,7 +301,7 @@ export function Lobby() {
(index: number) => {
const item = hierarchy[index];
if (!item) return index;
return `${space.roomId}:${item.space.roomId}:${item.space.depth}`;
return getSpaceHierarchyItemKey(space.roomId, item.space);
},
[hierarchy, space.roomId]
);
+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest';
import { getSpaceHierarchyItemKey } from './useSpaceHierarchy';
describe('getSpaceHierarchyItemKey', () => {
it('distinguishes hierarchy entries included through separate parents at the same depth', () => {
const firstHierarchyItem = {
roomId: '!child:example.com',
parentId: '!first-subspace:example.com',
content: { via: [] },
ts: 0,
depth: 1,
};
const secondHierarchyItem = {
...firstHierarchyItem,
parentId: '!second-subspace:example.com',
};
expect(getSpaceHierarchyItemKey('!space:example.com', firstHierarchyItem)).not.toBe(
getSpaceHierarchyItemKey('!space:example.com', secondHierarchyItem)
);
});
});
+3
View File
@@ -35,6 +35,9 @@ export type HierarchyItemRoom = {
export type HierarchyItem = HierarchyItemSpace | HierarchyItemRoom;
export const getSpaceHierarchyItemKey = (spaceId: string, item: HierarchyItem): string =>
`${spaceId}:${item.parentId ?? ''}:${item.roomId}:${item.depth}`;
type GetRoomCallback = (roomId: string) => Room | undefined;
const hierarchyItemSort: SortFunc<HierarchyItem> = (a, b) => {
+2 -2
View File
@@ -36,7 +36,7 @@ import { useCategoryHandler } from '$hooks/useCategoryHandler';
import { useNavToActivePathMapper } from '$hooks/useNavToActivePathMapper';
import { useRoomName } from '$hooks/useRoomMeta';
import type { HierarchyItem } from '$hooks/useSpaceHierarchy';
import { useSpaceJoinedHierarchy } from '$hooks/useSpaceHierarchy';
import { getSpaceHierarchyItemKey, useSpaceJoinedHierarchy } from '$hooks/useSpaceHierarchy';
import { allRoomsAtom } from '$state/room-list/roomList';
import { PageNavContent, PageNavHeader } from '$components/page';
import { PageNavShell } from '$components/page/PageNavShell';
@@ -779,7 +779,7 @@ export function Space() {
(index: number) => {
const item = hierarchy[index];
if (!item) return index;
return `${space.roomId}:${item.roomId}:${item.depth}`;
return getSpaceHierarchyItemKey(space.roomId, item);
},
[hierarchy, space.roomId]
);