Skip to content

Commit ebac9d5

Browse files
committed
fix: harden ColorSelect against empty options
`current` was derived as `options.find(...) ?? options[0]`, which is `undefined` when callers pass an empty array. Subsequent reads of `current.icon`/`current.label` then crash the render. This was masked locally (Svelte's reactive runtime swallows the error on some Node versions) but surfaced as an unhandled error on Node 20 in CI. Fall back to a placeholder option object so the button still renders.
1 parent 8d938be commit ebac9d5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

webview-ui/src/components/common/ColorSelect.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
let btnEl: HTMLButtonElement | undefined = $state();
2222
let dropdownStyle = $state('');
2323
24-
let current = $derived(options.find(o => o.value === value) ?? options[0]);
24+
// Callers can momentarily pass an empty options array — e.g., a parent
25+
// component that opens a modal before its store data lands, or a teardown
26+
// race where the source list is cleared while the dropdown is still
27+
// unmounting. Fall back to a placeholder so the template can render without
28+
// crashing on `current.icon` / `current.label`.
29+
let current = $derived(
30+
options.find(o => o.value === value)
31+
?? options[0]
32+
?? { value: '', label: '', color: '' }
33+
);
2534
2635
function toggle() {
2736
if (open) {

0 commit comments

Comments
 (0)