Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-sliding-sync-subspaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Fix a regression making subspaces with emote packs being listed as separate spaces on sliding-sync.
23 changes: 23 additions & 0 deletions src/client/slidingSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ describe('SlidingSyncManager room subscription coordination', () => {
it('uses the active subscription while a room is also an image-pack room', () => {
const manager = makeManager(makeMockMx());
const roomId = '!pack:example.com';
(manager as unknown as { listsFullyLoaded: boolean }).listsFullyLoaded = true;

manager.setImagePackSubscriptions([roomId]);
manager.subscribeToRoom(roomId);
Expand All @@ -346,6 +347,7 @@ describe('SlidingSyncManager room subscription coordination', () => {
it('restores the image-pack subscription when the room is no longer active', () => {
const manager = makeManager(makeMockMx());
const roomId = '!pack:example.com';
(manager as unknown as { listsFullyLoaded: boolean }).listsFullyLoaded = true;

manager.setImagePackSubscriptions([roomId]);
manager.subscribeToRoom(roomId);
Expand Down Expand Up @@ -400,6 +402,7 @@ describe('SlidingSyncManager room subscription coordination', () => {

it('removes image-pack subscriptions which are no longer configured', () => {
const manager = makeManager(makeMockMx());
(manager as unknown as { listsFullyLoaded: boolean }).listsFullyLoaded = true;

manager.setImagePackSubscriptions(['!old:example.com', '!current:example.com']);
manager.setImagePackSubscriptions(['!current:example.com']);
Expand All @@ -409,6 +412,26 @@ describe('SlidingSyncManager room subscription coordination', () => {
);
});

it('defers image-pack subscriptions until lists are loaded so pack spaces get the composite key', () => {
const manager = makeManager(makeMockMx());
const roomId = '!spacepack:example.com';

manager.setImagePackSubscriptions([roomId]);
expect(mocks.slidingSyncInstance.modifyRoomSubscriptions).not.toHaveBeenCalled();

manager.setSpaceSubscriptions([roomId]);
(manager as unknown as { listsFullyLoaded: boolean }).listsFullyLoaded = true;
(manager as unknown as { flushDeferredSubscriptions: () => void }).flushDeferredSubscriptions();

expect(mocks.slidingSyncInstance.useCustomSubscription).toHaveBeenLastCalledWith(
roomId,
'space_image_packs'
);
expect(mocks.slidingSyncInstance.modifyRoomSubscriptions).toHaveBeenLastCalledWith(
new Set([roomId])
);
});

it('registers the composite space+image-pack subscription', () => {
makeManager(makeMockMx());

Expand Down
10 changes: 10 additions & 0 deletions src/client/slidingSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ export class SlidingSyncManager {

private readonly imagePackRoomSubscriptions = new Set<string>();

private deferredImagePackSubscriptions: Set<string> | null = null;

private roomSubscriptionSyncQueued = false;

private readonly roomTimelineLimit: number;
Expand Down Expand Up @@ -998,6 +1000,10 @@ export class SlidingSyncManager {
const spaces = this.deferredSpaceSubscriptions;
this.deferredSpaceSubscriptions = new Set();
this.setSpaceSubscriptions(spaces);

const imagePacks = this.deferredImagePackSubscriptions;
this.deferredImagePackSubscriptions = null;
if (imagePacks) this.setImagePackSubscriptions(imagePacks);
}

private queueRoomSubscriptionSync(): void {
Expand Down Expand Up @@ -1053,6 +1059,10 @@ export class SlidingSyncManager {
public setImagePackSubscriptions(roomIds: Iterable<string>): void {
if (this.disposed) return;
const next = new Set(roomIds);
if (!this.listsFullyLoaded) {
this.deferredImagePackSubscriptions = next;
return;
}
const unchanged =
next.size === this.imagePackRoomSubscriptions.size &&
[...next].every((roomId) => this.imagePackRoomSubscriptions.has(roomId));
Expand Down
Loading