diff --git a/packages/grafana-ui/src/components/Combobox/useOptions.ts b/packages/grafana-ui/src/components/Combobox/useOptions.ts index ad160d6fb21..d35b8157b7a 100644 --- a/packages/grafana-ui/src/components/Combobox/useOptions.ts +++ b/packages/grafana-ui/src/components/Combobox/useOptions.ts @@ -65,10 +65,12 @@ export function useOptions(rawOptions: AsyncOptions>) => { let currentOptions: Array> = opts; if (createCustomValue && userTypedSearch) { - //Since the label of a normal option does not have to match its value and a custom option has the same value and label, - //we just focus on the value to check if the option already exists + // Since the label of a normal option does not have to match its value and a custom option has the same value and label, + // we just focus on the value to check if the option already exists const customValueExists = opts.some((opt) => opt.value === userTypedSearch); if (!customValueExists) { + // Make sure to clone the array first to avoid mutating the original array! + currentOptions = currentOptions.slice(); currentOptions.unshift({ label: userTypedSearch, value: userTypedSearch as T,