multiselect-case-bug-repro Svelte Themes

Multiselect Case Bug Repro

Reproduction repo for svelte-multiselect case-variant key bug

svelte-multiselect Case-Insensitive Key Bug Reproduction

The Problem

This repository demonstrates a bug in svelte-multiselect that crashed a production application.

When options have labels that differ only by case (e.g., "pd" and "PD"), the component crashes immediately on mount - even when each option has a unique UUID in the value field.

Svelte error: each_key_duplicate
Keyed each block has duplicate key `pd` at indexes 0 and 1

Quick Start

git clone https://github.com/davidamacey/multiselect-case-bug-repro.git
cd multiselect-case-bug-repro
npm install
npm run dev

Open http://localhost:5847

What You'll See

The demo shows three scenarios:

1. Case-Sensitive Mode (Working)

Uses key={(opt) => opt.value} to key by UUID. Allows "pd", "PD", and "Pd" as distinct selections.

2. Case-Insensitive Mode (Working)

Filters options to hide case variants after selection. Still uses UUID for keying.

3. Library Default (Crashes)

Check the "Show buggy default behavior" checkbox - the page crashes immediately because the default key function lowercases all labels, causing "pd", "PD", and "Pd" to all have the key "pd".

Root Cause

In svelte-multiselect/src/lib/MultiSelect.svelte, line 29:

key = (opt) => `${utils.get_label(opt)}`.toLowerCase()

This:

  1. Ignores the value field entirely (even when it contains unique UUIDs)
  2. Lowercases all labels, causing case-variant collisions
  3. Crashes Svelte's keyed {#each} blocks with duplicate keys

Why This Is Hard to Debug

  • The error points to Svelte internals, not svelte-multiselect
  • All UUIDs are unique - there are no actual duplicates in your data
  • No documentation warns about case-sensitivity in the key function
  • The app works fine until a user happens to create case-variant labels

Workaround

<MultiSelect
  {options}
  key={(opt) => opt.value}
/>

Suggested Fix

See ISSUE.md for the full issue report and suggested fixes.

Environment

  • svelte-multiselect: 11.5.2 (latest)
  • svelte: ^5.0.0
  • @sveltejs/kit: ^2.0.0
  • vite: ^6.0.0

Top categories

Loading Svelte Themes