Skip to content

Commit aac8fa1

Browse files
committed
Mitigation for gappy/limited sync responses in SPA mode
1 parent 83fa966 commit aac8fa1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/useReactions.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ export const ReactionsProvider = ({
184184
// This effect handles any *live* reaction/redactions in the room.
185185
useEffect(() => {
186186
const reactionTimeouts = new Set<number>();
187+
// TODO: this should be somewhere more sensible
188+
const handleTimelineReset = (): void => {
189+
logger.warn("Received TimelineReset indicating limited sync response");
190+
};
187191
const handleReactionEvent = (event: MatrixEvent): void => {
188192
// Decrypted events might come from a different room
189193
if (event.getRoomId() !== room.roomId) return;
@@ -297,6 +301,7 @@ export const ReactionsProvider = ({
297301
}
298302
};
299303

304+
room.on(MatrixRoomEvent.TimelineReset, handleTimelineReset);
300305
room.on(MatrixRoomEvent.Timeline, handleReactionEvent);
301306
room.on(MatrixRoomEvent.Redaction, handleReactionEvent);
302307
room.client.on(MatrixEventEvent.Decrypted, handleReactionEvent);
@@ -306,6 +311,7 @@ export const ReactionsProvider = ({
306311
room.on(MatrixRoomEvent.LocalEchoUpdated, handleReactionEvent);
307312

308313
return (): void => {
314+
room.off(MatrixRoomEvent.TimelineReset, handleTimelineReset);
309315
room.off(MatrixRoomEvent.Timeline, handleReactionEvent);
310316
room.off(MatrixRoomEvent.Redaction, handleReactionEvent);
311317
room.client.off(MatrixEventEvent.Decrypted, handleReactionEvent);

src/utils/matrix.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import { IndexedDBStore } from "matrix-js-sdk/src/store/indexeddb";
99
import { MemoryStore } from "matrix-js-sdk/src/store/memory";
1010
import {
1111
createClient,
12+
Filter,
1213
ICreateClientOpts,
1314
Preset,
15+
RoomEvent,
1416
Visibility,
1517
} from "matrix-js-sdk/src/matrix";
1618
import { ClientEvent } from "matrix-js-sdk/src/client";
@@ -165,7 +167,20 @@ export async function initClient(
165167
// Otherwise, a sync may complete before the listener gets applied,
166168
// and we will miss it.
167169
const syncPromise = waitForSync(client);
168-
await client.startClient({ clientWellKnownPollPeriod: 60 * 10 });
170+
await client.startClient({
171+
clientWellKnownPollPeriod: 60 * 10,
172+
// ask for a high limit to try and avoid gappy syncs
173+
filter: Filter.fromJson(undefined, "element-call", {
174+
room: {
175+
timeline: {
176+
limit: 1000,
177+
},
178+
},
179+
}),
180+
// we ask for 20 past message to try and get some recent context
181+
// n.b. past reactions are not guaranteed to be visible
182+
initialSyncLimit: 20,
183+
});
169184
await syncPromise;
170185

171186
return client;

0 commit comments

Comments
 (0)