fix(components): [select] Slot default invoked outside of the render (#23232)

* fix(components): [select] Slot default invoked outside of the render

* test: fix expect error

---------

Co-authored-by: rzzf <cszhjh@gmail.com>
This commit is contained in:
@长久同学
2026-02-26 15:26:39 +08:00
committed by GitHub
parent de70ad1ac9
commit 7475ac8eeb
2 changed files with 8 additions and 3 deletions

View File

@@ -62,7 +62,7 @@ describe('options', () => {
default: () =>
samples.map((_, i) => <ElOptionStub label={getLabel(i)} />),
})
expect(mockWarn).toHaveBeenCalled()
expect(mockWarn).not.toHaveBeenCalled()
vi.resetAllMocks()
await nextTick()
})
@@ -85,7 +85,7 @@ describe('options', () => {
</ElOptionGroupStub>
)),
})
expect(spy).toHaveBeenCalled()
expect(spy).not.toHaveBeenCalled()
vi.resetAllMocks()
})
})

View File

@@ -521,7 +521,12 @@ export default defineComponent({
})
}
watch(
() => [slots.default?.(), modelValue.value],
() => [
props.persistent || API.expanded.value || !slots.default
? undefined
: slots.default?.(),
modelValue.value,
],
() => {
// When persistent is false and the dropdown is closed, the menu is unmounted.
// We should always re-hydrate option data from slots so labels stay in sync