hotwired / turbo-rails

Use Turbo in your Ruby on Rails app
https://turbo.hotwired.dev
MIT License
2.13k stars 329 forks source link

8.0.5: cdn (and thus importmap pins) has broken import paths "CbGBsmqA.js" instead of cable.js #654

Closed zealot128 closed 2 months ago

zealot128 commented 4 months ago

I was trying to use Turbo-Rails with importmaps by using turbo installer, which downloaded the files into vendor. I then got error messages in the console about a missing file:

Started GET "/_/CbGBsmqA.js" for 127.0.0.1 at 2024-07-31 13:44:07 +0800
ActionController::RoutingError (No route matches [GET] "/_/CbGBsmqA.js"):

So I checked the vendor/javascript folder and found vendor/javascript/@hotwired--turbo-rails.js to be importing the specified file. Tried repinning, and saw that it downloaded from ga.jspm, so, you can see, the broken import is here too:

https://ga.jspm.io/npm:@hotwired/turbo-rails@8.0.5/app/javascript/turbo/index.js

import{s}from"../../../_/CbGBsmqA.js";export{c as cable}from"../../../_/CbGBsmqA.js";

seems to correlate with the cable.js import/export in https://github.com/hotwired/turbo-rails/blob/main/app/javascript/turbo/index.js

When checking previous version 8.0.4 https://ga.jspm.io/npm:@hotwired/turbo-rails@8.0.4/app/javascript/turbo/index.js

it seems that it inlines the whole consumer/cable stuff.

So I tried replacing the vendored file with 8.0.4 directly, as I found no way do "downgrade" using importmaps.

wget https://ga.jspm.io/npm:@hotwired/turbo-rails@8.0.4/app/javascript/turbo/index.js -O vendor/javascript/@hotwired--turbo-rails.js

And, the error is gone.

tjefferson08 commented 3 months ago

I was able to downgrade with:

bin/importmap pin @hotwired/turbo-rails@8.0.4

not sure if this is a designed/sanctioned feature but it worked!

jorgemanrubia commented 2 months ago

I released turbo@8.0.6 and then published turbo-rails@8.0.6 including it. I found some problems that look like a cache-propagation issue in npmjs. It's still not detecting 8.0.6 as the latest and, when forced, it hangs and eventually timeouts:

./bin/importmap pin @hotwired/turbo-rails@8.0.6

I also had some issues with npmjs failing to reflect the last version I had pushed for about 30 minutes. During my tests, I pushed two new versions for the turbo-rails gem (8.0.7 and 8.0.8). Once we sort this out, I'll align the turbo version with this one package.

I'll see if it's a matter of waiting a bit to see if npmjs picks the right version.

jorgemanrubia commented 2 months ago

I suspect the original problem here could be the package.json lacking an "export" section as explained here: https://jspm.org/jspm-dev-release#subpath-detection. When not provided, jspm infers which packages should be exported using some statistical analysis. It seems here it decided that cable.js was to be exported so it didn't inline them. I couldn't find any change on our side that could explain the change between 8.0.4 and 8.0.5.

I'll see if adding that helps.

jorgemanrubia commented 2 months ago

@zealot128 ok the problems with JSPM are sorted out now (see https://github.com/jspm/generator/pull/382).

Regarding the orginal problem, I think this fix did it, cable.js is inlined now:

https://ga.jspm.io/npm:@hotwired/turbo-rails@8.0.9/app/javascript/turbo/index.js

I'll bump turbo to match versions before closing this one.

jorgemanrubia commented 2 months ago

I just released v8.0.10 for turbo and turbo-rails and v2.0.8 for the gem.

zealot128 commented 2 months ago

@jorgemanrubia Awesome! Thanks for the investigation & quick fix!