-
Notifications
You must be signed in to change notification settings - Fork 754
react-rails incompatible with browserify workflow #129
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
Comments
Hmm, I can't tell that this is related, but here's what jumped out at me: When you pass a component name to (I'm not sure why this would cause |
I'm making some progress, but this gem is putting up a fight. I did get a bare bones component to render, buuuuut... The I isolated my header file into its own folder for now and specified that in
It seems like any changes to the javascripts files needs a server restart to take place, which slows down progress. I tried pointing the components directly to my browserify-built bundle.js file, but I realized I have things specified with browserify-shim so they don't get built into the bundle. For example, in my package.json I have:
And I include underscore on the page in a regular script tag so it's cached from a cdn. That means underscore isn't built into bundle.js. I'm going to try putting my deps into the the My test suite executes some of the files using node, which of course works fine because Right now this gem seems incompatible with a real React workflow. I'm going to keep fiddling with it and see if I can find any tricky ways to get require to work. |
Hi! I'd like to help, but I think mostly I've just got bad news.
This is how Rails expects things to work. You read the file extensions backwards and apply pre-processors in order. You can do crazy things, like
This is because we're stuck with the Rails Asset Pipeline. JavaScript is parsed on the server-side using ExecJS, another Rails core component. From the ExecJS FAQ:
There's really not much we can do about that without requiring some non-standard Rails libraries, which IMO is beyond the scope of this gem. If you really need
Again, this is a limitation of ExecJS: for server rendering in a Rails environment to work, components.js needs to include the component in a way that makes it globally accessible. Theoretically, only the "top" component needs to be reachable globally, the rest can be hidden away.
Are you working off the master branch? If so, this is a bug, you should not need to restart the server every time a file needs to be changed. If you can create a reproducable case, I can take a look at it.
Rails Asset Pipeline has it's own workflow for requiring dependencies in order. If you add We're stuck with the Asset Pipeline, because that's what Basecamp likes. Theoretically, you could have a "side build" based around Node + g(ulp|runt), with components.js as your output target. So long as you made your top-level component globally available, ExecJS should be able to figure it out. |
👏 👏 |
Speaking of "side builds," it looks like @bogdan-dumitru in issue #120 has a pretty good build going. |
Maybe this article could help you out: https://medium.com/@olance/rails-react-browserify-e315001d5974 ? |
Would it be possible to have a separate browserify bundle |
Sounds like there are a few OK workarounds! |
I'm getting an eval error on rendering hitting a page.
I see this in my server logs:
Template code:
components.js:
templates/Header.js:
If I remove the
prerendered => true
I get the empty div outputted to the page, no errors. I'm intentionally not using react in the rails asset pipeline, I have react installed with npm. But the react_component tag works without prerender.Gemfile:
My header component builds fine with browserify so the dependency tree isn't the issue. How can I figure out what's going on here?
The text was updated successfully, but these errors were encountered: