Remove debug logs with DOM queries

This commit is contained in:
Cohee
2025-06-05 08:25:50 +00:00
parent e1a1fdb0da
commit 0f9cd5f48d

View File

@@ -1943,23 +1943,20 @@ function clearEntryList() {
if (!$list.children().length) { if (!$list.children().length) {
console.warn('List already empty, skipping cleanup.'); console.debug('List already empty, skipping cleanup.');
console.timeEnd('clearEntryList'); console.timeEnd('clearEntryList');
return; return;
} }
// Step 1: Clean all <option> elements within <select> // Step 1: Clean all <option> elements within <select>
console.warn(`Before cleaning: ${$list.find('option').length} options in list`);
$list.find('option').each(function () { $list.find('option').each(function () {
const $option = $(this); const $option = $(this);
$option.off(); $option.off();
$.cleanData([$option[0]]); $.cleanData([$option[0]]);
$option.remove(); $option.remove();
}); });
console.warn(`Post-clean: ${$list.find('option').length} options in list`);
// Step 2: Clean all <select> elements // Step 2: Clean all <select> elements
console.warn(`Before cleaning: ${$list.find('select').length} selects in list`);
$list.find('select').each(function () { $list.find('select').each(function () {
const $select = $(this); const $select = $(this);
// Remove Select2-related data and container if present // Remove Select2-related data and container if present
@@ -1967,7 +1964,7 @@ function clearEntryList() {
try { try {
$select.select2('destroy'); $select.select2('destroy');
} catch (e) { } catch (e) {
console.warn('Select2 destroy failed:', e); console.debug('Select2 destroy failed:', e);
} }
} }
const $container = $select.parent(); const $container = $select.parent();
@@ -1975,47 +1972,34 @@ function clearEntryList() {
$container.find('*').off(); $container.find('*').off();
$.cleanData($container.find('*').get()); $.cleanData($container.find('*').get());
$container.remove(); $container.remove();
} else {
console.warn('container not found');
console.warn($select.parent().html());
} }
// Destroy Select2 if applicable
$select.off(); $select.off();
$.cleanData([$select[0]]); $.cleanData([$select[0]]);
}); });
console.warn(`Post-clean: ${$list.find('select').length} selects in list`);
// Step 3: Clean <div>, <span>, <input> // Step 3: Clean <div>, <span>, <input>
console.warn(`Before cleaning: ${$list.find('div, span, input').length} divs, spans, inputs in list`);
$list.find('div, span, input').each(function () { $list.find('div, span, input').each(function () {
const $elem = $(this); const $elem = $(this);
$elem.off(); $elem.off();
$.cleanData([$elem[0]]); $.cleanData([$elem[0]]);
$elem.remove(); $elem.remove();
}); });
console.warn(`Post-clean: ${$list.find('div, span, input').length} divs, spans, inputs in list`);
// Destroy Sortable // Destroy Sortable
console.warn(`Before cleaning: ${$list.sortable('instance') ? 1 : 0} sortable instance in list`);
if ($list.sortable('instance')) { if ($list.sortable('instance')) {
$list.sortable('destroy'); $list.sortable('destroy');
} }
console.warn(`Post-cleaning: ${$list.sortable('instance') ? 1 : 0} sortable instance in list`);
let totalElementsOfanyKindLeftInList = $list.children().length; let totalElementsOfanyKindLeftInList = $list.children().length;
// Final cleanup // Final cleanup
if (totalElementsOfanyKindLeftInList !== 0) { if (totalElementsOfanyKindLeftInList !== 0) {
console.time('empty'); console.time('empty');
console.warn(`Before .empty(): ${totalElementsOfanyKindLeftInList} elements left in list`);
$list.empty(); $list.empty();
totalElementsOfanyKindLeftInList = $list.children().length; totalElementsOfanyKindLeftInList = $list.children().length;
console.warn(`After .empty(): ${totalElementsOfanyKindLeftInList} elements left in list`);
console.timeEnd('empty'); console.timeEnd('empty');
} else {
console.warn('Entry List is already totally empty, no need to call .empty()');
} }
console.timeEnd('clearEntryList'); console.timeEnd('clearEntryList');