-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Description
Version
3.5.25
Reproduction link
Steps to reproduce
- Note the empty state "Nothing Selected"
- Click the "Set value to 1" button
- Click the "Set value to null" button
What is expected?
The value passed to the custom element should be null and "Nothing Selected" is rendered.
What is actually happening?
The value is converted to 0 before passing it to custom element and "First Selected" is rendered.
We (me and @per-toyra-stratsys) stumbled upon this potential issue when building manual Vue wrappers for a web component list box. undefined is used to represent that nothing is selected and is a valid value to pass to the web component. The offending code is probably https://github.com/vuejs/core/blob/v3.5.25/packages/runtime-dom/src/modules/props.ts#L58-L71.
The issue is broader than the reproduction shows. Other notable issues when prop changes type:
- When a prop changes from
trueto''the value is changed totrueso nothing happens. - When a prop is changed from
'a'tonullthe value is changed to''.
null and undefined both trigger the same condition so null is used for clarity in the reproduction.
We can work around the issue by manually setting the property of the web component in a onBeforeUpdate hook so that the check here https://github.com/vuejs/core/blob/v3.5.25/packages/runtime-dom/src/modules/props.ts#L59 returns undefined.