question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange behaviour with select and default value

See original GitHub issue

Steps to reproduce

I’ve created a new rails app 5.1 and add react-rails 2.4.3:

rails new ciccio
cd ciccio
echo "gem 'react-rails'" >> Gemfile
bundle
rails g react:install
rails g scaffold post title body:text
rails db:migrate

I’ve create a simple React component Hello.jsx

class Hello extends React.Component { 
  render() {
    return(
      <div>
        <select defaultValue={1}>
          <option value={1}>Select this to set value to {1}</option>
          <option value={2}>Select this to set value to {2}</option>
        </select>
      </div>
    )
  }
}

And I render this component on app/views/posts/index.html.erb

<%= react_component('Hello', {}, {prerender: true}) %>

Expected behavior

When I visit the page http://localhost:3000/posts I should see the select and nothing on console.log

Actual behavior

In console.log I get Warning: Text content did not match. Server: "Select this to set value to 1" Client: "Select this to set value to "

System configuration

Sprockets version: 3.7.1 React-Rails version: 2.4.3 Rails version: 5.1 Ruby version: 2.4.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
p-salidocommented, Dec 24, 2017

@pioz If you don’t have React Dev Tools installed, first step in troubleshooting this is to install them and inspect actual props passed to the select tag.

0reactions
alkesh26commented, Nov 10, 2022

No updates on this for a long time. Closing this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange behaviour in Select defaultValue · Issue #3483 - GitHub
Hi , i am trying solve a problem, which is related to defaultValue's strange behaviour. I have 2 select components which are handled...
Read more >
Oracle showing strange behaviour while populating default ...
1. Default values are only used when a column is not referenced in an insert statement. · 2. If the column is referenced,...
Read more >
Solved: Dropdown default value inconsistent
I'm attempting to set the 'default' value from a. ... This odd behaviour is pretty reliable in its bizzare way. Why would some...
Read more >
Strange behavior of select element when choosing options
Normally when you click on a select element, the option you have selected is highlighted by default and as you scroll to other...
Read more >
Very strange behaviour of Form::select() - Laracasts
This is two cases with different behaviour. In the first: select box will always have a default value. Why Form::select() ignores default value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found