From 27e7ff92ae57ca1150c3223c8d6d01fa2b7ef899 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 18 Nov 2026 11:49:32 +0100 Subject: [PATCH] fix(utils): only match `null` with `null` in `compare` --- src/runtime/utils/index.ts | 4 ++++ test/utils/index.spec.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/runtime/utils/index.ts b/src/runtime/utils/index.ts index c07bf11a07..c23e2bf7fb 100644 --- a/src/runtime/utils/index.ts +++ b/src/runtime/utils/index.ts @@ -80,6 +80,10 @@ export function compare(value?: T, currentValue?: T, comparator?: string | (( return false } + if (value === null || currentValue === null) { + return value === currentValue + } + if (typeof value === 'string') { return value === currentValue } diff --git a/test/utils/index.spec.ts b/test/utils/index.spec.ts index 48754f25bb..402a938973 100644 --- a/test/utils/index.spec.ts +++ b/test/utils/index.spec.ts @@ -125,6 +125,12 @@ describe('compare', () => { expect(compare({ id: 1 }, { id: 2 }, 'id')).toBe(false) }) + it('only matches null with null', () => { + expect(compare({ label: 'Status' }, null, 'value')).toBe(false) + expect(compare({ id: 1 }, null, (a, b) => a.id === b.id)).toBe(false) + expect(compare(null, null, 'value')).toBe(true) + }) + it('falls back to deep equality', () => { expect(compare({ a: [1] }, { a: [1] })).toBe(true) expect(compare({ a: 1 }, { a: 2 })).toBe(false) @@ -176,6 +182,10 @@ describe('getDisplayValue', () => { expect(getDisplayValue(items, 2, { valueKey: 'value', labelKey: 'label' })).toBe('Two') }) + it('does not match a label item for a null value with `by`', () => { + expect(getDisplayValue([{ type: 'label', label: 'Status' }, ...items], null, { by: 'value', labelKey: 'label' })).toBeUndefined() + }) + it('reads `labelKey` from an object value', () => { expect(getDisplayValue(items, { value: 3, label: 'Three' }, { labelKey: 'label' })).toBe('Three') expect(getDisplayValue(items, { value: 3, label: 'Three' })).toBeUndefined()