Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select options behaving differently in Vue 3 than Vue 2 #3475

Closed
Livijn opened this issue Mar 24, 2021 · 3 comments · Fixed by #3477
Closed

Select options behaving differently in Vue 3 than Vue 2 #3475

Livijn opened this issue Mar 24, 2021 · 3 comments · Fixed by #3477
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working

Comments

@Livijn
Copy link

Livijn commented Mar 24, 2021

Version

3.0.7

Reproduction link

Vue 3:
https://codesandbox.io/s/distracted-ritchie-kdcwo?file=/src/App.vue

Vue 2:
https://codesandbox.io/s/focused-glade-qj11z?file=/src/App.vue

Steps to reproduce

Click the submit button in both sandboxes

What is expected?

The <option> with value null shouldn't be rendered as a string in Vue 3.

What is actually happening?

When you add a couple of <option>, eventually an <option> with value null will be rendered as a it has a string value of null.

<!-- Vue 2 -->
<select name="large">
  <option value="">Not set</option>
  ...
</select>

<!-- Vue 3 -->
<select name="large">
  <option value="null">Not set</option>
  ...
</select>
@posva posva added 🐞 bug Something isn't working 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Mar 24, 2021
@Justineo
Copy link
Member

Justineo commented Mar 24, 2021

https://github.com/vuejs/vue-next/blob/eb1fae63f926435fb0eef890663d24e09d4c79e1/packages/compiler-dom/src/transforms/stringifyStatic.ts#L73-L85

As we can see if you have more than 4 <option>s, Vue's compiler will try to stringify static nodes for performance reasons. So when you have 5 <option>s, the first <option> is stringified into "<option value=\"null\">Not set</option>" so we are experiencing the current issue.

Template Explorer →

@Justineo
Copy link
Member

There seems to be another bug that <option :value="null"> is rendered as <option value> when not taking the optimization path as for Vue 3 we have taken a new strategy for attribute coercion and the expected output should be <option> as null values for an attribute now indicates the attribute should be removed.

@Justineo
Copy link
Member

Though #3477 may fix that null values were rendered as "null", the difference between Vue 2 and 3 still exists and is intentional.

And there's still an issue to be investigated that <option :value="null"> is rendered as <option value="">, which does not comply with our latest coercion behavior.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants