mirror of https://github.com/zulip/zulip.git
list_widget: Check length of JQuery collection instead of collection
itself. We were checking for the undefined value of `$html_item` but this variable is always true since `$.find` never returns an undefined value and it returns a JQuery collection instead. So we need to check the length of that JQuery collection here to make sure that the condition works as expected.
This commit is contained in:
parent
ed7588152e
commit
d58085dde2
|
@ -287,7 +287,7 @@ export function create<Key = unknown, Item = Key>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const $html_item = meta.$scroll_container.find(opts.html_selector(item));
|
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
|
// We don't have the item in the current scroll container; it'll be
|
||||||
// rendered with updated data when it is scrolled to.
|
// rendered with updated data when it is scrolled to.
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -674,7 +674,10 @@ run_test("render item", () => {
|
||||||
const regex = new RegExp(`\\<tr data-item=${item}\\>.*?<\\/tr\\>`);
|
const regex = new RegExp(`\\<tr data-item=${item}\\>.*?<\\/tr\\>`);
|
||||||
assert.ok(expected_queries.includes(query));
|
assert.ok(expected_queries.includes(query));
|
||||||
if (query.includes(`data-item='${INITIAL_RENDER_COUNT}'`)) {
|
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 {
|
||||||
// Return a JQuery stub for the original HTML.
|
// Return a JQuery stub for the original HTML.
|
||||||
|
@ -685,6 +688,7 @@ run_test("render item", () => {
|
||||||
called = true;
|
called = true;
|
||||||
$container.$appended_data.replace(regex, new_html);
|
$container.$appended_data.replace(regex, new_html);
|
||||||
},
|
},
|
||||||
|
length: 1,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue