Open TylerRick opened 3 years ago
I would love to see this and this gem move forward.
If the auto adding is removed completly the gem would be a lot easier.
It is a nice feature but tends to break and adds a lot of comlexity.
If the user adds the JavaScript and the xray_bar then the methods like script_matcher
append_js!
can go away.
Maybe there could be a Verision 1.0:
I like your idea, @rocket-turtle . Sad to see this project languish...
In both a real app that I just upgraded to sprockets 4 and the
spec/dummy
app in this project, I noticed thatjavascript_include_tag "application"
no longer injects a separate script tag forjquery
.With Sprockets 3, this line:
in
spec/dummy/app/assets/javascripts/application.js
used to result in separate script tags being emitted, like this:But now with Sprockets 4, it concatenates everything and just emits this instead:
(BTW, I've already adjusted the script matching to account for new
.debug
suffix, in #101)That's fine. Concatenating them into a single script is what it should be doing (at least in production). I still don't understand what was making it emit the separate jquery.js line before — or why xray-rails is designed to depends on that line being there to even work properly.
Maybe the
Rails.application.config.assets.debug
is what caused it to split that into sub-assets in dev before? But that is still set to true. So maybe sprockets/rails changed that behavior.Workaround
Whatever the case, as a workaround for now, this is what I did in my real app:
I just included the xray script directly, because I know jquery is included in my application.js script, and since xray-rails no longer adds that for me.
Inside this project, I worked around it slightly differently (in #101):
... because the tests are still testing to make sure that xray.js gets added automatically, and if I just included
then it would no longer be testing that xray.js gets added automatically (which might be okay — maybe we should just remove that feature).
What's a better solution?
Personally, I'm starting to think that the feature where it automatically adds xray.js to the document is more trouble than it's worth.
I propose that we remove that automatic feature and just make it part of the install instructions that you need to add this line to your template/layout:
Sure, zero-config one-click installs are nice and all, but:
I guess that's why this branch exists — to give you that flexibility:
I guess I'm just wondering why we should even bother keeping the other (add xray.js after jquery.js) branch. Is it really worth it?
It might have been a fair enough assumption back in the olden days (2012), but these days (with use of webpack in Rails projects the norm, etc.), it doesn't make as much sense. For that matter, why not remove the dependency on jQuery entirely (#111)?
What about projects using webpack for JS instead of sprockets?
We should also think about what the right way to include xray into a project if it is using webpack for JS (which I understand is the default way in Rails 6, though I have not upgraded yet in my apps) instead of sprockets...
In that case, we will have the same problem: the template will have a line like this:
which will not add a separate script tag for jquery.js either.
(See also #106)