From 70a80fe0cb84994ceb51da0cf3919b72230ff808 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 11 Feb 2025 16:28:11 +0000 Subject: [PATCH 1/3] Don't reload roomview on offline connectivity check Doesn't look like this was a regression as far as I can see, but you did have to switch rooms while offline for it to start happening. There's no use reloading the room until we're online again. Fixes https://github.com/element-hq/element-web/issues/29072 --- src/components/structures/RoomView.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index a64b118c2c3..ed54161b35c 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1151,13 +1151,14 @@ export class RoomView extends React.Component { break; case "MatrixActions.sync": if (!this.state.matrixClientIsReady) { + const isReadyNow = Boolean(this.context.client?.isInitialSyncComplete()); this.setState( { - matrixClientIsReady: !!this.context.client?.isInitialSyncComplete(), + matrixClientIsReady: isReadyNow, }, () => { // send another "initial" RVS update to trigger peeking if needed - this.onRoomViewStoreUpdate(true); + if (isReadyNow) this.onRoomViewStoreUpdate(true); }, ); } From c823861a6bb8740103ee475d4a7827aed4bac537 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 11 Feb 2025 17:04:26 +0000 Subject: [PATCH 2/3] Add regression test --- .../components/structures/RoomView-test.tsx | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/unit-tests/components/structures/RoomView-test.tsx b/test/unit-tests/components/structures/RoomView-test.tsx index 3f60e3564fe..6a17326498c 100644 --- a/test/unit-tests/components/structures/RoomView-test.tsx +++ b/test/unit-tests/components/structures/RoomView-test.tsx @@ -223,6 +223,31 @@ describe("RoomView", () => { expect(instance.getHiddenHighlightCount()).toBe(0); }); + // Regression test for https://github.com/element-hq/element-web/issues/29072 + it("does not force a reload on sync unless the client is coming back online", async () => { + cli.isInitialSyncComplete.mockReturnValue(false); + + const instance = await getRoomViewInstance(); + const onRoomViewUpdateMock = jest.fn(); + (instance as any).onRoomViewStoreUpdate = onRoomViewUpdateMock; + + act(() => { + // As if a connectivity check happened (we are still offline) + defaultDispatcher.dispatch({ action: "MatrixActions.sync" }, true); + // ...so it still should not force a reload + expect(onRoomViewUpdateMock).not.toHaveBeenCalledWith(true); + }); + + act(() => { + // set us to online again + cli.isInitialSyncComplete.mockReturnValue(true); + defaultDispatcher.dispatch({ action: "MatrixActions.sync" }, true); + }); + + // It should now force a reload + expect(onRoomViewUpdateMock).toHaveBeenCalledWith(true); + }); + describe("when there is an old room", () => { let instance: RoomView; let oldRoom: Room; From 0711cf0ceeb0bfa712b3fe29ada0c173381282ea Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 11 Feb 2025 17:29:19 +0000 Subject: [PATCH 3/3] Move it down the file to avoid changing the snapshots --- .../components/structures/RoomView-test.tsx | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/test/unit-tests/components/structures/RoomView-test.tsx b/test/unit-tests/components/structures/RoomView-test.tsx index 6a17326498c..70febb2c1b5 100644 --- a/test/unit-tests/components/structures/RoomView-test.tsx +++ b/test/unit-tests/components/structures/RoomView-test.tsx @@ -223,31 +223,6 @@ describe("RoomView", () => { expect(instance.getHiddenHighlightCount()).toBe(0); }); - // Regression test for https://github.com/element-hq/element-web/issues/29072 - it("does not force a reload on sync unless the client is coming back online", async () => { - cli.isInitialSyncComplete.mockReturnValue(false); - - const instance = await getRoomViewInstance(); - const onRoomViewUpdateMock = jest.fn(); - (instance as any).onRoomViewStoreUpdate = onRoomViewUpdateMock; - - act(() => { - // As if a connectivity check happened (we are still offline) - defaultDispatcher.dispatch({ action: "MatrixActions.sync" }, true); - // ...so it still should not force a reload - expect(onRoomViewUpdateMock).not.toHaveBeenCalledWith(true); - }); - - act(() => { - // set us to online again - cli.isInitialSyncComplete.mockReturnValue(true); - defaultDispatcher.dispatch({ action: "MatrixActions.sync" }, true); - }); - - // It should now force a reload - expect(onRoomViewUpdateMock).toHaveBeenCalledWith(true); - }); - describe("when there is an old room", () => { let instance: RoomView; let oldRoom: Room; @@ -718,6 +693,31 @@ describe("RoomView", () => { expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ action: Action.RoomLoaded }); }); + // Regression test for https://github.com/element-hq/element-web/issues/29072 + it("does not force a reload on sync unless the client is coming back online", async () => { + cli.isInitialSyncComplete.mockReturnValue(false); + + const instance = await getRoomViewInstance(); + const onRoomViewUpdateMock = jest.fn(); + (instance as any).onRoomViewStoreUpdate = onRoomViewUpdateMock; + + act(() => { + // As if a connectivity check happened (we are still offline) + defaultDispatcher.dispatch({ action: "MatrixActions.sync" }, true); + // ...so it still should not force a reload + expect(onRoomViewUpdateMock).not.toHaveBeenCalledWith(true); + }); + + act(() => { + // set us to online again + cli.isInitialSyncComplete.mockReturnValue(true); + defaultDispatcher.dispatch({ action: "MatrixActions.sync" }, true); + }); + + // It should now force a reload + expect(onRoomViewUpdateMock).toHaveBeenCalledWith(true); + }); + describe("when there is a RoomView", () => { const widget1Id = "widget1"; const widget2Id = "widget2";