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

Likely issue with rails 6.1.0-alpha #54

Open
josh-m-sharpe opened this issue Jun 13, 2020 · 9 comments
Open

Likely issue with rails 6.1.0-alpha #54

josh-m-sharpe opened this issue Jun 13, 2020 · 9 comments

Comments

@josh-m-sharpe
Copy link

Using rails 00c2d3e1e61093451a00b1b70548cfd9ae549c53 as of this writing.

2020-06-13T18:37:54+00:00: Rack app error handling request { GET /assets/admin-c9569c117d1107474494012b3a255f49a3570eedd08e51123008d0412abc93cb.js }
#<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x000055dc97100c10>>
/app/vendor/bundle/ruby/2.6.0/gems/heroku-deflater-0.6.3/lib/heroku-deflater/serve_zipped_assets.rb:31:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/sendfile.rb:110:in `call'
/app/vendor/bundle/ruby/2.6.0/bundler/gems/rails-c13d46937445/actionpack/lib/action_dispatch/middleware/host_authorization.rb:76:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/sentry-raven-2.13.0/lib/raven/integrations/rack.rb:51:in `call'
/app/vendor/bundle/ruby/2.6.0/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'

I'd guess this is related to this commit, which not only removes the match? method - it does away with FileHandler in favor of Static

@sedubois
Copy link

sedubois commented Nov 4, 2020

I also got this issue when upgrading my Rails app to 6.1.0.rc1:

2020-11-04 16:26:31 +0100 Rack app ("GET /assets/application-d202e7f926ea26f1a77ad108db4187a078d7c86bebf0e97e4fe24242cdc9c487.css" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007f9009c58d48>>
2020-11-04 16:26:31 +0100 Rack app ("GET /assets/application-3e190496dea178b3bbd482d5809118b541c5a13462d8fccbe725158cbeac7d92.js" - (127.0.0.1)): #<NoMethodError: undefined method `match?' for #<ActionDispatch::FileHandler:0x00007f9009c58d48>>
...

CSS/JS assets can't load so the system tests generate screenshots with only HTML and no styling applied. I also get errors such as error: ReferenceError: $ is not defined because of this. I did not notice the issue when running the app in development because I load this gem as follows: gem 'heroku-deflater', group: [:production, :test].

However I believe my app actually does not need this. I'm not sure which one does the job, but between the app being deployed on Heroku and having CloudFlare in front of this, I checked that when I remove this gem heroku-deflater, deploy to production, and check the traffic with the browser dev tools, there is still a response header content-encoding: br. Also, my vague understanding is that if compression needed to be done within Rails, it could be achieved by adding config.middleware.insert_after ActionDispatch::Static, Rack::Deflater to config/application.rb. I would just have liked to have a way to test to guarantee that compression is happening, something I could do before when using this gem (I had written a test taking inspiration from this post).

@atstockland
Copy link

I am experiencing this issue with Rails 6.1 on heroku.

@romanbsd
Copy link
Owner

I don't have time to support this at the moment, but I'll be happy to receive a PR.

@pungerfreak
Copy link

If I'm understanding this correctly, the functionality provided by the class ServeZippedAssets is now built into ActionDispatch::Static. It seems probable that has been the case for some time, but since nothing was breaking we never noticed it.

@romanbsd introduced this feature in 2013, here, and Rails introduced this in 2014 and then improved it over the years to offer much of the same abilities as @romanbsd baked into his. But the recent refactor of that class removed the interface this gem expected. To maintain expected behavior, it seems like a simple major/minor version check could be added and bypass this in the case of Rails 6.1+.

I'll gladly put together a PR if I'm on the right track.

ps - It seems there may be other aspects of this gem that are baked into Rails now, but I don't have time to dig through.

@JunichiIto
Copy link

JunichiIto commented Feb 13, 2021

I got the same error, but I found I should have changed the setting below:

 # config/application.rb
-config.load_defaults 6.0
+config.load_defaults 6.1

I could solve the issue with this change.

Oh sorry, that was not the solution. The issue still exists😣

MikeMcQuaid added a commit to github/opensourcefriday that referenced this issue Mar 9, 2021
It's broken on Rails 6.1 and probably not needed any more:
romanbsd/heroku-deflater#54
@xxx
Copy link

xxx commented Mar 20, 2021

Could someone please clarify if this gem is useful for Rails 6.1+?

We're also in a state where removing the gem makes our app work after upgrading to 6.1, but I'm trying to figure out if I should continue to follow this gem, or if it's obsolete.

@mtmail
Copy link

mtmail commented Mar 20, 2021

On our website with Rails 6.1 it became obsolete. We removed it. And added config.middleware.use Rack::Deflater in config/application.rb instead.

@jsaraiva
Copy link

jsaraiva commented Mar 20, 2021

I also removed it, and replaced it with:

config.middleware.use Rack::Deflater,
  include: Rack::Mime::MIME_TYPES.select{|k, v| v =~ /text|json|javascript/ }.values.uniq,
  if: lambda {|env, status, headers, body| body.body.length > 512 }

require 'rack/brotli'

config.middleware.use Rack::Brotli,
  include: Rack::Mime::MIME_TYPES.select{|k, v| v =~ /text|json|javascript/ }.values.uniq,
  if: lambda {|env, status, headers, body| body.body.length > 512 },
  deflater: {
    quality: 1
  }

at the end of application.rb. Note that the Brotli middleware requires the rack-brotli gem.

This encodes javascript, css, and html with Brotli (if supported as per the request's Accepts header), or GZip otherwise.

@jjb
Copy link

jjb commented Mar 4, 2022

other discussion: #32 #37

jcowhigjr added a commit to jcowhigjr/yelp_search_demo that referenced this issue Jul 5, 2022
jcowhigjr added a commit to jcowhigjr/yelp_search_demo that referenced this issue Jul 5, 2022
jcowhigjr added a commit to jcowhigjr/yelp_search_demo that referenced this issue Jul 17, 2022
* Added compression in production on heroku

testing this out as the propshaft asset compiler is only minifying currently
and it looks like I would need cssbundler and jsbundler to handle this otherwise

* pulled in some updates to the heroku compress gem

* added exporter adapter and sprockets ... who knows??!?

* found a bug about returning 500 error for some assets .. this might fix it

https://fuzzyblog.io/blog/rails/2022/06/02/rails-7-madness-no-such-middleware-to-insert-before-actiondispatch-static.html

* removing the heroku asset exporter since it doesn't work

* revmoved the heroku stuff

* reverting to the original configuration

* sprockets  exporter

* added fork of heroku-deflater that is upgraded for rail 6.1 assets

* test that heroku deflator is no longer required

romanbsd/heroku-deflater#54 (comment)

* explicitly set when to use Rack:Deflator / Brotli

romanbsd/heroku-deflater#54 (comment)

* attempt to constrain the use of the compressors

* Updated bin/dev and bin/prod to switch back and forth between a prod and dev like experience.
Added details of ngrok to DevNotes for remote access to localhost
Added notes about setting the same ENV variables that are used in Heroku using the dotenv gem and  .env.production
Removed the interfont stylesheet link that was very large and not loading during  production  testing
Added a database config section to use the osx local Postgres.app but in production the DATABASE_URL will override this
The prod script 'builds' the app like in heroku and 'deploys' it to https://jitter.test with precompiled assets

* Update of Gemfile.lock
Added example of the heroku environment variables to copy to .env.production for bin/prod script

* added a script to make testing prod simpler with bin/puma-dev-prod
added clearer explanation about secrets to Devnotes
added the dotenv-rails gem to support setting env variables like heroku does
enabled access to ENV['HOST'] to support requests from https://jitter.prod or ngrok urls

* added and extra layer of security for the production enviroment to filter  requests passed from the ENV['host'] for example jitter.prod and from  x-feature.herokuapp.com
 fixed a typo that showed up in the preview environment

this kinda stinks but for heroku previewapps and ngrok apps we can't predict the subdomain to set ENV['HEROKU_APP_NAME']

* adjusted the config since production is blocked

* grrr.. this is still blocking requests in heroku

* added scripts to use https://jitter.test which is using rails development mode
added scripts to use https://jitter.prod which builds like heroku deployment and uses postgres and local bundle and cached classes etc
added some explanation in the DevNotes
upgraded a security fix that is actually pretter urgent from two days ago
pupulated the .env.production with the heroku configs with and explanation and heroku sample since this is git ignored to protect secrets
ngrok still needs a little debugging but for this PR i just needed the prod like build to work to examine the host.config problem in heroku

* ENV['Host'] is working for jitter.prod locally but the hosts 403 error is still happening on heroku .. so trying som things

* determined that the 403 error is coming from the default_url_options combined with config.hosts.   Added the HEROKU_APP_NAME to fix this

* ugghh fixed typo in herokuapp.com
matchu added a commit to matchu/r-neopets-dream-pets that referenced this issue Sep 4, 2022
We were getting errors like the ones described here, and followed the instructions provided!
romanbsd/heroku-deflater#54
dbackeus added a commit to dbackeus/raagtime that referenced this issue Sep 5, 2022
Also:
- Decaffinate CoffeeScript to plain ES
- Rewrite sass into vanilla CSS
- Load js dependencies via CDN
- Remove heroku-deflater (romanbsd/heroku-deflater#54)
seanmack added a commit to seanmack/kicksplash that referenced this issue Sep 12, 2023
Moves CSS from static files in the `public/assets` folder to the asset
pipeline.

Notes:

* I removed the `heroku-deflater` gem due to an asset compilation bug I
encountered on Heroku. The gem has [an open
issue](romanbsd/heroku-deflater#54), but it
doesn't seem worth worrying about right now (I'll likely use Cloudflare
eventually, which will handle the PageSpeed requirement for gzip
compression).
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

No branches or pull requests

10 participants