Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
list_widget: Drop the row of an item rerendered past the rendered range.
Aman Agrawal638e8db26719
diff --git a/web/src/list_widget.ts b/web/src/list_widget.tsindex cd934e19345..acb8de7e1b4 100644--- a/web/src/list_widget.ts+++ b/web/src/list_widget.ts@@ -495,6 +495,18 @@ export function create<Key, Item = Key>(return;}+ // An item moved past the rendered range no longer belongs on screen:+ // its row would not be counted by meta.offset, and a later render()+ // would append the item again. filtered_list holds what get_item+ // returned, so the item is not found when get_item builds a fresh+ // object each time, as for the bots tables; those rows are updated+ // in place.+ const index = meta.filtered_list.indexOf(item);+ if (index !== -1 && index >= meta.offset) {+ remove_row($html_item);+ return;+ }+const html = opts.modifier_html(item, meta.filter_value);if (typeof html !== "string") {blueslip.error("List item is not a string", {item: html});diff --git a/web/tests/list_widget.test.cjs b/web/tests/list_widget.test.cjsindex f6470d83618..77a7d727788 100644--- a/web/tests/list_widget.test.cjs+++ b/web/tests/list_widget.test.cjs@@ -187,9 +187,11 @@ function make_items(count) {}// A widget over `list` with a stand-in for its DOM: `rows` holds the items-// that have a row, in order, and refuses to render an item twice.+// that have a row, in order, and refuses to render an item twice; `stats`+// counts the redraws that threw rendered rows away.function make_tracked_widget(list, opts = {}) {const rows = [];+ const stats = {redraws: 0};function items_in(html) {return html.matchAll(/data-item=(\d+)/g)@@ -215,6 +217,9 @@ function make_tracked_widget(list, opts = {}) {}};$container.empty = () => {+ if (rows.length > 0) {+ stats.redraws += 1;+ }rows.length = 0;};const $scroll_container = make_scroll_container();@@ -227,7 +232,7 @@ function make_tracked_widget(list, opts = {}) {$simplebar_container: $scroll_container,...opts,});- return {widget, rows};+ return {widget, rows, stats};}run_test("scrolling", () => {@@ -1059,6 +1064,28 @@ run_test("filter_and_sort removes rows of items no longer listed", () => {assert.equal(render_count, 3);});+run_test("render_item drops the row of an item moved past the rendered range", () => {+ const list = make_items(100);+ const {widget, rows, stats} = make_tracked_widget(list, {init_sort: (a, b) => a.key - b.key});+ const moved = rows[4];++ // The item now sorts last, past the rendered range: its row goes, with+ // no redraw, and the rendered list still matches the rows in the DOM.+ moved.key = 200;+ widget.filter_and_sort();+ widget.render_item(moved);+ assert.ok(!rows.includes(moved));+ assert.equal(rows.length, INITIAL_RENDER_COUNT - 1);+ assert.equal(stats.redraws, 0);+ assert.deepEqual(widget.get_rendered_list(), rows);++ // Rendering the rest reaches it last, and once.+ widget.render(list.length);+ assert.ok(widget.all_rendered());+ assert.equal(rows.length, list.length);+ assert.equal(rows.at(-1), moved);+});+run_test("Multiselect dropdown retain_selected_items", () => {const $container = make_container();const $scroll_container = make_scroll_container();