Avoid excessive re-render when setting same reference/value in snapshot (#32918)

* perf: avoid excessive re-render when setting same value in snapshot

* test: update tests
This commit is contained in:
Florian Duros
2026-03-25 15:23:11 +00:00
committed by GitHub
parent d0a564d578
commit 1025d60001
5 changed files with 25 additions and 5 deletions
@@ -280,7 +280,7 @@ describe("EventContentBodyViewModel", () => {
expect(vm.getSnapshot().body).toBe("Updated");
});
it("emits updates when setters are called with unchanged values", () => {
it("doesn't emit updates when setters are called with unchanged values", () => {
const replacer = jest.fn();
mockedCombineRenderers.mockReturnValue(() => replacer);
mockedBodyToNode.mockReturnValue({
@@ -298,7 +298,7 @@ describe("EventContentBodyViewModel", () => {
vm.setEventContent(undefined, defaultContent);
vm.setAs("span");
expect(subscriber).toHaveBeenCalledTimes(2);
expect(subscriber).toHaveBeenCalledTimes(0);
expect(vm.getSnapshot()).toEqual(previousSnapshot);
});
@@ -80,7 +80,7 @@ describe("ReactionsRowButtonViewModel", () => {
expect(listener).toHaveBeenCalledTimes(1);
expect(tooltipSetPropsSpy).not.toHaveBeenCalled();
vm.setCount(5);
vm.setCount(6);
expect(listener).toHaveBeenCalledTimes(2);
});
@@ -86,7 +86,7 @@ describe("ReactionsRowViewModel", () => {
expect(onAddReactionContextMenu).toHaveBeenCalledWith(clickEvent);
});
it("emits only for setters that always merge when values are unchanged", () => {
it("doesn't emit only setters that always merge when values are unchanged", () => {
const vm = createVm();
const previousSnapshot = vm.getSnapshot();
const listener = jest.fn();
@@ -99,7 +99,7 @@ describe("ReactionsRowViewModel", () => {
// `setReactionGroupCount` is optimized and skips emit for unchanged derived values.
// The other setters always merge and therefore emit.
expect(listener).toHaveBeenCalledTimes(3);
expect(listener).toHaveBeenCalledTimes(0);
expect(vm.getSnapshot()).toEqual(previousSnapshot);
});
});