Skip to content

select v-model does not set option selected attribute in rendered HTML using SSR #5339

Closed
@benneq

Description

@benneq

Version

3.2.29

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Create a template with <select v-model="..."> and some <option :value="..."> elements. And then look at the rendered HTML. There will never be a selected attribute on the option elements.

When loading the SSR rendered page with disabled JavaScript it will always select the first option, because no option in the HTML is actually selected.

What is expected?

Similar behavior to <input v-model="...">. For input elements this will insert a value="..." attribute.
Though <select v-model="..."> should insert a selected attribute for the selected option element. (Or elements when using <select multiple>).

What is actually happening?

No selected attribute is added to the SSR rendered HTML.


A workaround is to set :selected manually:

<select v-model="selected">
  <option disabled value="">Please select one</option>
  <option value="A" :selected="selected === 'A'">A</option>
  <option value="B" :selected="selected === 'B'">B</option>
  <option value="C" :selected="selected === 'C'">C</option>
</select>

Metadata

Metadata

Assignees

No one assigned

    Labels

    🍰 p2-nice-to-havePriority 2: this is not breaking anything but nice to have it addressed.🐞 bugSomething isn't workinghas workaroundA workaround has been found to avoid the problemscope: ssr

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions