Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

list_widget: Check length of JQuery collection instead of collection itself.

Lalitd58085dde265
diff --git a/web/src/list_widget.ts b/web/src/list_widget.ts
index 24465b028ee..77eb129c032 100644
--- a/web/src/list_widget.ts
+++ b/web/src/list_widget.ts
@@ -287,7 +287,7 @@ export function create<Key = unknown, Item = Key>(
return;
}
const $html_item = meta.$scroll_container.find(opts.html_selector(item));
- if (!$html_item) {
+ if ($html_item.length === 0) {
// We don't have the item in the current scroll container; it'll be
// rendered with updated data when it is scrolled to.
return;
diff --git a/web/tests/list_widget.test.js b/web/tests/list_widget.test.js
index bfbbff01f37..aecfc1c5f73 100644
--- a/web/tests/list_widget.test.js
+++ b/web/tests/list_widget.test.js
@@ -674,7 +674,10 @@ run_test("render item", () => {
const regex = new RegExp(`\\<tr data-item=${item}\\>.*?<\\/tr\\>`);
assert.ok(expected_queries.includes(query));
if (query.includes(`data-item='${INITIAL_RENDER_COUNT}'`)) {
- return undefined; // This item is not rendered, so we find nothing
+ // This item is not rendered, so we find nothing so return an empty stub.
+ return {
+ length: 0,
+ };
}
return {
// Return a JQuery stub for the original HTML.
@@ -685,6 +688,7 @@ run_test("render item", () => {
called = true;
$container.$appended_data.replace(regex, new_html);
},
+ length: 1,
};
};