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

views of .js.es6.jsx not hot-reloading #13

Open
travisdmathis opened this issue Nov 10, 2016 · 8 comments
Open

views of .js.es6.jsx not hot-reloading #13

travisdmathis opened this issue Nov 10, 2016 · 8 comments

Comments

@travisdmathis
Copy link

travisdmathis commented Nov 10, 2016

added an initializer and added file type to react_rails_hot_loader.rb but no joy :(

Any ideas?

[HotLoader] updating: intern_badges.js.es6.jsx
[HotLoader] update finished

but the content doesn't reload.. i have to manually refresh.

@travisdmathis travisdmathis changed the title content of .js.es6.jsx not hot-reloading views of .js.es6.jsx not hot-reloading Nov 10, 2016
@rmosolgo
Copy link
Owner

Loading consists of:

  • Executing the JavaScript in the updated file
  • Calling ReactRailsUJS.mountComponents() to re-mount components in views.

This only works if the global reference to the component (eg MyApp.MyComponent) was updated by executing the JS in that file.

Is that true in this case, does intern_batches.js update the global reference to the component? If you're not sure, feel free to share the contents of the file.

@kevgathuku
Copy link

Sadly, I'm experiencing the same with a .js.jsx file with only one component.
The [HotLoader] logs are shown on the console but I have to manually refresh to see the updated content.
Where can I find the intern_batches.js file to see what's going on?
Thanks in advance.

@rmosolgo
Copy link
Owner

rmosolgo commented Jan 5, 2017

intern_badges.js.es6.jsx is a file in travisdmathis's app. It's the component that isn't reloading properly.

@kevgathuku, if you'd like to share some details, I'd be happy to debug with you. Here is some useful info you could share:

  • The call to react_component(...) in your Rails view, showing the component name and props
  • The source code of the component which doesn't update
  • The log messages from [HotLoader]

@kevgathuku
Copy link

Thanks for clarifying @rmosolgo
The log messages are shown below:
screen shot 2017-01-05 at 2 07 13 pm

Here's a repo with the project in question:
https://github.com/kevgathuku/rails-react-demo

The call to react_component is in https://github.com/kevgathuku/rails-react-demo/blob/master/app/views/site/index.html.erb
The component itself is: https://github.com/kevgathuku/rails-react-demo/blob/master/app/assets/javascripts/components/main.js.jsx

@rmosolgo
Copy link
Owner

rmosolgo commented Jan 5, 2017

Thanks for the details!

I think that the HotLoader just flat-out doesn't work with require.

It works by reloading the jsx file (in this case, main.js.jsx), which reloads the module in isolation, but doesn't require it again. So the new definition of Main is never re-attached to window, and react_component("Main") doesn't have access to it.

I wonder how this could be addressed. Somehow, we have to reload the "manifest", too (components.js), since that's where the components are actually attached to window 🤔

@kevgathuku
Copy link

Hmm..that seems interesting.
I currently don't have any idea how to approach such a problem given I am new to the Ruby and Rails ecosystem, but I am familiar with JavaScript.
Any idea how I could help?

@travisdmathis
Copy link
Author

i apologize, i missed this update, and I'm no longer working on this project, it has since been completed so don't have any access to work w/ this any further.. I'm also not using react-rails anymore so..

@xifengzhu
Copy link

I also encountered the same problem. Anyone known how to fix it?

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

4 participants