fix(sase): VIN filter buildHref — dangling-else bug

For string filter values (q, success, sort, etc.), the URL query string
came out empty — array values (provider, status with multi-select)
worked. Root cause was a brace-less if/for/if chain:

  if (Array.isArray(v)) for (const item of v) if (item) usp.append(k, item);
  else usp.set(k, String(v));

JS associates the `else` with the inner `if (item)`, not the outer
`if (Array.isArray(v))`. So when v is a string, the outer if is false,
nothing runs, usp stays empty, and the URL becomes just "?". The status
pills and the "Ara" search button both looked broken because their
patches were string-typed.

Same buildHref in users/_query.ts already had braces, which is why
the user list search was unaffected.

Add the missing braces. Also drops the temporary console.log
diagnostics from the VIN filter bar.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Semih
2026-05-19 08:58:54 +03:00
parent dbdc0d476b
commit 091e9daa2f
2 changed files with 5 additions and 22 deletions

View File

@@ -35,27 +35,13 @@ export function VinsFilterBar({ initial }: { initial: VinsSearchParams }) {
};
function nav(patch: Partial<VinsSearchParams>) {
const merged = { ...current, ...patch };
const href = `${pathname}${buildHref(current, { page: undefined, ...patch })}`;
// eslint-disable-next-line no-console
console.log(
"[VinsFilterBar.nav] patch=" +
JSON.stringify(patch) +
" current=" +
JSON.stringify(current) +
" merged=" +
JSON.stringify(merged) +
" href=" +
href,
);
startTransition(() => router.push(href));
}
function submitSearch(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
const q = query.trim();
// eslint-disable-next-line no-console
console.log("[VinsFilterBar.submit]", { q, queryState: query });
nav({ q: q || undefined });
}

View File

@@ -17,18 +17,15 @@ export function buildHref(
...patch,
} as Record<string, string | string[] | undefined>;
const usp = new URLSearchParams();
const trace: string[] = [];
for (const [k, v] of Object.entries(merged)) {
trace.push(`${k}=${JSON.stringify(v)}(${typeof v})`);
if (v === undefined || v === null || v === "") continue;
if (Array.isArray(v)) for (const item of v) if (item) usp.append(k, item);
else usp.set(k, String(v));
if (Array.isArray(v)) {
for (const item of v) if (item) usp.append(k, item);
} else {
usp.set(k, String(v));
}
}
const qs = usp.toString();
// eslint-disable-next-line no-console
if (typeof window !== "undefined") {
console.log("[buildHref] entries=", trace.join(" | "), "qs=", qs);
}
return qs ? `?${qs}` : "?";
}