Skip to content

Commit 595f393

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

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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,
1415
Visibility,
@@ -165,7 +166,20 @@ export async function initClient(
165166
// Otherwise, a sync may complete before the listener gets applied,
166167
// and we will miss it.
167168
const syncPromise = waitForSync(client);
168-
await client.startClient({ clientWellKnownPollPeriod: 60 * 10 });
169+
await client.startClient({
170+
clientWellKnownPollPeriod: 60 * 10,
171+
// ask for a high limit to try and avoid gappy syncs
172+
filter: Filter.fromJson(undefined, "element-call", {
173+
room: {
174+
timeline: {
175+
limit: 1000,
176+
},
177+
},
178+
}),
179+
// we ask for 20 past message to try and get some recent context
180+
// n.b. past reactions are not guaranteed to be visible
181+
initialSyncLimit: 20,
182+
});
169183
await syncPromise;
170184

171185
return client;

0 commit comments

Comments
 (0)