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.

Multiple mount component with fresh rails app and Turbolinks

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 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:

Screen

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
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
piozcommented, Feb 6, 2018

The issue is fixed for me! Thank you for your work!

1reaction
BookOfGregcommented, Dec 14, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

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