Version
3.5.25
Reproduction link
jsfiddle.net
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
true to '' the value is changed to true so nothing happens.
- When a prop is changed from
'a' to null the 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.
Version
3.5.25
Reproduction link
jsfiddle.net
Steps to reproduce
What is expected?
The value passed to the custom element should be
nulland"Nothing Selected"is rendered.What is actually happening?
The value is converted to
0before 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.
undefinedis 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:
trueto''the value is changed totrueso nothing happens.'a'tonullthe value is changed to''.nullandundefinedboth trigger the same condition sonullis used for clarity in the reproduction.We can work around the issue by manually setting the property of the web component in a
onBeforeUpdatehook so that the check here https://github.com/vuejs/core/blob/v3.5.25/packages/runtime-dom/src/modules/props.ts#L59 returnsundefined.