Multiple mount component with fresh rails app and Turbolinks
See original GitHub issueSteps 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 scaffold post title body:text
rails db:migrate
I’ve create a simple React component Hello.jsx
class Hello extends React.Component {
componentDidMount() {
console.log("MOUNTED")
}
componentWillUnmount() {
console.log("UNMOUNT")
}
render() {
console.log("RENDER")
return(<span>Hello</span>)
}
}
And I render this component on app/views/posts/index.html.erb
<%= react_component('Hello') %>
Expected behavior
When I change page with turbolinks and return on a previous page with a React component the component should mount one time only.
Actual behavior
Look at this gif:
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:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
React Component not rendered properly with Turbolinks in ...
This is quite a complex issue, and I am afraid I don't think it has a straightforward answer. I will explain as best...
Read more >How To Set Up a Ruby on Rails v5 Project with a React ...
With your Home component in place, you will now set up routing using React Router. Create a routes directory in the app/javascript directory:....
Read more >Digging into Turbo with Ruby on Rails 7 - YouTube
When Rails 7 made its first appearance in December of 2021 a new default component was introduced called Turbo. If you have any...
Read more >How To Use Turbolinks to Make Fast Rails Apps - Speedshop
As a result, in the post-V8 era, many developers think traditional server-side languages and frameworks (Ruby, Python, even Java) are simply too ...
Read more >Server-side apps with client-side rendering - Jonathan Reinink
These days there are two common architectural approaches to modern web app development: Server-side rendered apps (Rails, Laravel, Django).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue is fixed for me! Thank you for your work!
Thanks a bunch for the detailed report! I’ll look into this and let you know.
Edit: Marked this as an enhancement rather than bug (although obviously buggy) as this seems more inconvenient rather than breaking for most cases. I do intend on fixing this.