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

4.0.0.beta9 causes Sprockets::FileNotFound for vendor asset #613

Closed
felixbuenemann opened this issue Jun 13, 2019 · 9 comments · Fixed by #614
Closed

4.0.0.beta9 causes Sprockets::FileNotFound for vendor asset #613

felixbuenemann opened this issue Jun 13, 2019 · 9 comments · Fixed by #614

Comments

@felixbuenemann
Copy link
Contributor

After upgrading from Sprockets 4.0.0.beta8 to 4.0.0.beta9 I receive the following error:

Sprockets::FileNotFound: could not find file: /assets/javascripts/jquery.js
/Users/felix/.rvm/gems/ruby-2.6.1/gems/sprockets-4.0.0.beta9/lib/sprockets/loader.rb:140:in `load_from_unloaded'
/Users/felix/.rvm/gems/ruby-2.6.1/gems/sprockets-4.0.0.beta9/lib/sprockets/loader.rb:59:in `block in load'
/Users/felix/.rvm/gems/ruby-2.6.1/gems/sprockets-4.0.0.beta9/lib/sprockets/loader.rb:334:in `fetch_asset_from_dependency_cache'
/Users/felix/.rvm/gems/ruby-2.6.1/gems/sprockets-4.0.0.beta9/lib/sprockets/loader.rb:43:in `load'
/Users/felix/.rvm/gems/ruby-2.6.1/gems/sprockets-4.0.0.beta9/lib/sprockets/cached_environment.rb:44:in `load'
/Users/felix/.rvm/gems/ruby-2.6.1/gems/sprockets-4.0.0.beta9/lib/sprockets/base.rb:96:in `find_all_linked_assets'
/Users/felix/.rvm/gems/ruby-2.6.1/gems/sprockets-4.0.0.beta9/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'

After dissecting the git history I found the following commit to cause the problem 36741c6 (Thread-safe cache loader) and the last working commit to be 1844ee9.

I'm using Sprockets with Rails 5.2.3 on Ruby 2.6.1 on macOS 10.14.

@felixbuenemann
Copy link
Contributor Author

A similar issue has been reported in #609.

@schneems
Copy link
Member

schneems commented Jun 13, 2019 via email

@felixbuenemann
Copy link
Contributor Author

I can't reproduce it in the standalone app, but it looks like the cache key for the unloaded asset is wrong on 4.0.0.beta9 vs beta8.

If I inspect the key assigned from unloaded.dependency_history_key at the beginning of fetch_asset_from_dependency_cache it appears to be truncated (missing binary data after source:):

# beta8
=> "asset-uri-cache-dependencies:vendor/assets/javascripts/jquery.js?type=application/javascript&pipeline=source:\xB0\xCFb0,\xF8\xAA\x19,\xDA$\xA02\xF3\x0EJ\x82N\xFD\xF3\xF0gL\xC8\xBC\xE3;a\xB2W\xD6\x06"
# beta9
=> "asset-uri-cache-dependencies:vendor/assets/javascripts/jquery.js?type=application/javascript&pipeline=source:"

If I manually fix the key to the beta8 value using pry on beta9, then the asset is found in the cache:

pry(#<Sprockets::CachedEnvironment>)> cache.get "asset-uri-cache-dependencies:vendor/assets/javascripts/jquery.js?type=application/javascript&pipeline=source:\xB0\xCFb0,\xF8\xAA\x19,\xDA$\xA02\xF3\x0EJ\x82N\xFD\xF3\xF0gL\xC8\xBC\xE3;a\xB2W\xD6\x06"
=> [#<Set: {"environment-version",
  "environment-paths",
  "rails-env",
  "processors:type=application/javascript&file_type=application/javascript&pipeline=source",
  "file-digest://vendor/assets/javascripts/jquery.js"}>]

@felixbuenemann
Copy link
Contributor Author

felixbuenemann commented Jun 13, 2019

OK, it looks like unloaded.filename differs:

# beta8
=> "/Users/felix/dev/sites/myapp/vendor/assets/javascripts/jquery.js"
# beta9
=> "/assets/javascripts/jquery.js"

This causes the call to @env.file_digest(filename) in dependency_history_key to return nil.

@felixbuenemann
Copy link
Contributor Author

felixbuenemann commented Jun 13, 2019

Also the uri differs, which is used to derive the filename:

# beta8
=> "file:///Users/felix/dev/sites/myapp/vendor/assets/javascripts/jquery.js?type=application/javascript&pipeline=source"
# beta9
=> "file://vendor/assets/javascripts/jquery.js?type=application/javascript&pipeline=source"

So it looks like on beta8 the path is absolute, while on beta9 it is relative to the rails root.

@schneems
Copy link
Member

schneems commented Jun 13, 2019 via email

@felixbuenemann
Copy link
Contributor Author

@schneems As I've written before, I couldn't reproduce the bug in a standalone app yet.

It looks like all the uris from asset links in find_all_linked_assets of lib/sprockets/base.rb use relative paths to the rails root on beta9, but absolute paths on beta8.

@felixbuenemann
Copy link
Contributor Author

@schneems Found it, there's a missing line in asset_from_cache:

expand_key_from_hash(asset[:metadata], :links)

I'll make a PR with the bugfix.

felixbuenemann added a commit to felixbuenemann/sprockets that referenced this issue Jun 13, 2019
This fixes a regression from 36741c6 where a line was missed in the
conversion.

Fixes rails#613
@schneems
Copy link
Member

Right you are, good find! Thanks a ton for reporting and investigating! Would love to add a general purpose test for the expansion behavior. We have one for compression behavior here https://github.com/rails/sprockets/pull/547/files#diff-89c067b041f282dfcf6e1a6725536317R432

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

Successfully merging a pull request may close this issue.

2 participants