wicked_pdf
wicked_pdf copied to clipboard
Adding wicked_pdf leads to fatal error on any render
Issue description
Added wicked_pdf + wkhtmltopdf-binary to gemfile of existing spa project Generated wicked initializer with default config Startup application Try to render any page (not ones that are invoking wicked pdf):
[a7a7e671-2c8c-4e2a-8274-aadef48292b2]
[a7a7e671-2c8c-4e2a-8274-aadef48292b2] FrozenError (can't modify frozen fatal):
[a7a7e671-2c8c-4e2a-8274-aadef48292b2]
Expected or desired behavior
No error occuring?
System specifications
wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf
):
cat Gemfile.lock | grep wicked_pdf
wicked_pdf (1.4.0)
wicked_pdf
wkhtmltopdf version (output of wkhtmltopdf --version
):
bundle exec wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)
whtmltopdf provider gem and version if one is used:
cat Gemfile.lock | grep wkhtmltopdf
wkhtmltopdf-binary (0.12.5)
wkhtmltopdf-binary
platform/distribution and version (e.g. Windows 10 / Ubuntu 16.04 / Heroku cedar): Mac OS X Mojave 10.14.6
When you say this is an SPA, do you mean that this is Rails running in API mode (no view rendering). If so, this thread has some tips for that.
What version of Ruby and Rails are you running?
No, it does have simplistic view rendering, in which we wrap react pages.
ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
bundle exec rails -v
Rails 6.0.0
Can you try and point your Gemfile at the master branch and see if that helps? I very recently merged a Rails 6 comparatively PR, but haven’t released it yet.
Gave it a go, unfortunately I get the same fatal FrozenError. Tried to increase my log level to debug but no futher info exposed.
While trying to research it, I did find someone else had this issue with the gem: https://stackoverflow.com/questions/55301110/frozen-error-when-trying-to-run-rails-application
Perhaps a deprecation error failing somewhat silently: https://github.com/rails/rails/pull/37088 (not released yet I think)
Thanks for that extra context. The comment that this is being raised as the result of a SystemStackError seems like a decent explanation. This gem has some incompatibilities with other gems that try to do similar thing by either prepending or alias_method_chaining of render
. I intend to allow you to disable this behavior eventually.
Here are some threads that may help you determine what gem could be interfering, and some tips to work around this: https://github.com/mileszs/wicked_pdf/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+SystemStackError
Let me know how it goes. If you keep having trouble, I'm sure I can help you out (probably with a monkeypatch or something), just let me know.
@unixmonkey I am also having this same issue. On my machine I get a FrozenError: can't modify frozen fatal
and my teammate is getting an interpreter crash. We noticed that the issue happened when ActiveSupport.on_load
was introduced and were able to work around this by monkey patching wicked_pdf railtie, completely removing that code, and manually including the helpers in controllers and view helpers where needed. Specifically, I think ActionController::Base.send :prepend, PdfHelper
is causing it for us because removing that line makes it so that FrozenError
is not thrown. Any idea as to what's going on?
I had the same when including gem 'wicked_pdf'
to my Rails 5 application. It seems the latest version of Wicked PDF depends on Rails 6, could this be a similar problem?
@bo-oz I don't think Rails 5 compatibility has anything to do with your issue. I've tested with Rails 5 and the current version. I have seen incompatibility with other gems that also override render
, like the "remotipart" gem.
If this is your issue, there are some suggestions in #650 that may help you track it down.
Hi Guys, any update on this?
same for us 🤷🏿
it's because we override def render
of application controller
# def render(*args)
# response.set_header('Original-User', User.find(session[:original_user_id]).name) if session[:original_user_id]
# super
# end
if i comment it, it works. if i use my override, it's an infinity loop
Hi there, I was facing this exact same problem on version 1.4.0. Upgrading to 2.6.3 solved the problem for me.
I've found out that when overriding the render method caused WickedPdf::PdfHelper
to loop back to itself on this file lib/wicked_pdf/pdf_helper.rb:46
method(:render).super_method.call(options, *args, &block)
Anyway, here we are using Rails 6.1 with Ruby 2.7