brentd / xray-rails

☠️ A development tool that reveals your UI's bones
MIT License
1.22k stars 79 forks source link

must require xray javascript manually? #64

Closed nextekcarl closed 8 years ago

nextekcarl commented 8 years ago

I have a Rails 4.2.5.1 app that's already using Jquery, and I stumbled upon this gem today. Added to development group, bundled, removed tmp assets, double checked config.assets.debug was set to true, restarted the app, and tried cmd+shift+x and nothing. Checked console, nothing. Checked html source, found comments for xray wrapping code and figured that's a fallback option for me, but no js file being included on the page.

So I manually required xray in my application.js, reloaded, and I now see the xray message in my console, and the shortcut works! Awesome! Except I can't deploy to heroku like this since it can't find the file to include during precompile phase since I can't tell it to not include that file outside development.

Is there something else I might be missing here? The app doesn't use backbone. It seems like everything is working except the automatic require. As soon as I remove the require, it stops working.

mattbrictson commented 8 years ago

The xray-rails gem is supposed to automatically inject its JavaScript file into the response. It does this with a middleware that parses the response, finds where jQuery is being included, and inserts its JavaScript after that.

This process is automatic and solves the deployment issues you mentioned, but it the parse+insert step is a bit brittle. If your jQuery isn't in a file called "jquery", for example, that may be the problem. Or you might have found a bug.

Maybe you could paste the HTML source of your app's <head> that gets sent to the browser and we can figure out why xray-rails is failing to find jQuery and perform the insertion of its own JS.

nextekcarl commented 8 years ago

I'm actually using jQuery2, so maybe that's the problem?

<script src="/assets/jquery2.self-a4777c1acac0a74340755725342901a54ed000955bf6f5320491b8b2514c86ec.js?body=1"></script>
<script src="/assets/jquery_ujs.self-d456baa54c1fa6be2ec3711f0a72ddf7a5b2f34a6b4f515f33767d6207b7d4b3.js?body=1"></script>
<script src="/assets/jquery.countdown.min.self-7438de4717ee05bd2b2f56a30b1d4ff0bc562b031fd81fa80253457e8f761da1.js?body=1"></script>
<script src="/assets/jquery.singlePageNav.min.self-ea7214737c231c2754a39e74273816eda7a80f80dd4277402cb93c2cbd3646b8.js?body=1"></script>
<script src="/assets/jquery.superslides.min.self-0b5e8d70f7de04e5d1ed2a3410f03d73e5758a8707e120c0aece5af80a05eff6.js?body=1"></script>
<script src="/assets/custom.self-1c9050b98e5c346281862204a740128f39a823a92fad41816610ff35123f454a.js?body=1"></script>
<script src="/assets/wow.min.self-0d561dc583d8790bbe0d603b2f35c0021c14803d47ad8439b743a4d799821d1d.js?body=1"></script>
<script src="/assets/d3.self-8689d534a532bc8db6847d6391ca254ba3955aa7fb9499442b0986738a066574.js?body=1"></script>
<script src="/assets/registration.self-85db92e3836c9b18e766b352296e8cafa64f0e1505c4e2f2911b7238eb16022a.js?body=1"></script>
<script `src="/assets/application.self-16c207b3ca1b52afcfc7f4b662487caf1bbe084a6656bb15f693ab9de2d11be7.js?body=1"></script>

Originally, after reading your comment, I thought it was that I'm including most of my javascripts outside of the head, at the end of my page, for performance reasons, but even after making this change it still isn't working, so I'm think it doesn't look for jQuery2.js?

mattbrictson commented 8 years ago

Agreed, it probably is because xray-rails isn't looking for jQuery2.js.

nextekcarl commented 8 years ago

Is this something you plan on adding? I can't be the only one using jQuery2, can I?

mattbrictson commented 8 years ago

I'm sure the maintainers of the project would accept a PR if you're willing to submit one. I'm just a fellow user of xray-rails that is trying to help as best I can.

nextekcarl commented 8 years ago

Ha, you were so helpful I assumed you were a maintainer. I'll get right on that, @mattbrictson

mattbrictson commented 8 years ago

Fixed by #65

mattbrictson commented 8 years ago

Ha, you were so helpful I assumed you were a maintainer.

I am now (as of this week). 😄

nextekcarl commented 8 years ago

Ha, I just reread this issue and was getting really confused. Great news.