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

Strange behaviour with select and default value #851

Closed
pioz opened this issue Dec 15, 2017 · 5 comments
Closed

Strange behaviour with select and default value #851

pioz opened this issue Dec 15, 2017 · 5 comments

Comments

@pioz
Copy link

pioz commented Dec 15, 2017

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

@BookOfGreg
Copy link
Member

Is this issue, the way React handles forms? https://reactjs.org/docs/forms.html#the-select-tag

@p-salido
Copy link

@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.

@mabid
Copy link

mabid commented Feb 6, 2018

I investigated this issue, it is not a react-rails issue but an issue in react's hydrate. The issue has been fixed here facebook/react#11602

@BookOfGreg
Copy link
Member

Thanks @mabid , once I'm notified there's a new release of react, I'll update the pre-bundle for sprockets users.

@alkesh26
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants