Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autocomplete arraysEqual leading to loops #1433

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions frontend/src/lib/components/Forms/AutocompleteSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@
dispatch('cache', selected);
}

function arraysEqual(arr1: (string | undefined)[], arr2: (string | undefined)[]) {
if (arr1?.length !== arr2?.length) return false;

const set1 = new Set(arr1);
const set2 = new Set(arr2);
function arraysEqual(
arr1: string | (string | undefined)[] | null | undefined,
arr2: string | (string | undefined)[] | null | undefined
): boolean {
const normalize = (val: string | (string | undefined)[] | null | undefined) => {
if (typeof val === 'string') return [val];
return val ?? [];
};

const a1 = normalize(arr1);
const a2 = normalize(arr2);

if (a1.length !== a2.length) return false;

const set1 = new Set(a1);
const set2 = new Set(a2);

for (const value of set1) {
if (!set2.has(value)) return false;
Expand Down
Loading