Don't reload roomview on offline connectivity check (#29243)

* 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

* Add regression test

* Move it down the file to avoid changing the snapshots
This commit is contained in:
David Baker
2025-02-11 20:34:32 +00:00
committed by GitHub
parent f7b010a0b3
commit 53c97dfa50
2 changed files with 28 additions and 2 deletions

View File

@@ -1151,13 +1151,14 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
break; break;
case "MatrixActions.sync": case "MatrixActions.sync":
if (!this.state.matrixClientIsReady) { if (!this.state.matrixClientIsReady) {
const isReadyNow = Boolean(this.context.client?.isInitialSyncComplete());
this.setState( this.setState(
{ {
matrixClientIsReady: !!this.context.client?.isInitialSyncComplete(), matrixClientIsReady: isReadyNow,
}, },
() => { () => {
// send another "initial" RVS update to trigger peeking if needed // send another "initial" RVS update to trigger peeking if needed
this.onRoomViewStoreUpdate(true); if (isReadyNow) this.onRoomViewStoreUpdate(true);
}, },
); );
} }

View File

@@ -693,6 +693,31 @@ describe("RoomView", () => {
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith({ action: Action.RoomLoaded }); 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", () => { describe("when there is a RoomView", () => {
const widget1Id = "widget1"; const widget1Id = "widget1";
const widget2Id = "widget2"; const widget2Id = "widget2";